Rails4:范围中的关联布尔值



我在两个模型之间有一个has_and_belongs_to_many关系,我想写一个范围来检查该关系上的布尔值是否为真:

class Component
  has_and_belongs_to_many :templates
  scope :editable, -> { where(template.showable) }
  ....
end

Template模型上,:showable是一个布尔值。我如何在Rails4中写这篇文章?

scope :editable, -> { joins(:templates).where( templates: { showable: true } ) }

最新更新