【发布时间】:2018-10-10 00:09:04
【问题描述】:
我有一个类 ImageCollection,它的状态可以是“活动”。此类属于一个 Image,该 Image 有一个名为“workflow_state”的属性。
我有以下工作但需要几秒钟才能执行:
def self.published
where(status: STATUS_ACTIVE).select { |x| x.image.workflow_state == Publishable::Meta.published_key }
end
以下不起作用:
scope :published, lambda {
where(status: STATUS_ACTIVE).joins(:image).where(
'image.workflow_state = ?', Publishable::Meta.published_key
)
}
然后返回:
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'image.workflow_state' in 'where clause': SELECT `image_containers`.* FROM `image_containers` INNER JOIN `images` ON `images`.`id` = `image_containers`.`image_id` WHERE `image_containers`.`status` = 'active' AND (image.workflow_state = 'published') ORDER BY `image.containers`.`id` ASC LIMIT 1
我很困惑,因为图像表有一个 workflow_state
非常感谢任何帮助
【问题讨论】:
-
谢谢你——如果你把它作为答案发布,我会在允许的时候接受它:)
标签: ruby-on-rails ruby rails-activerecord