循环遍历对象以查找匹配项

时间:2013-01-15 12:30:33

标签: ruby-on-rails loops rails-activerecord

我有一个Shift和一个Type表,其中包含以下关系:

class Shift < ActiveRecord::Base
  belongs_to :type
end

class Type < ActiveRecord::Base
  has_many :shifts, :dependent => :destroy
end

Type表有一个名为Unassignable的属性。

我想执行一个查询,该查询返回属于Shifts属性为Type的{​​{1}}的所有Unassignable

像: Shift.where(:shift.type.unassignable =&gt; true)

任何帮助:)

由于

1 个答案:

答案 0 :(得分:1)

Shift.includes(:type).where("types.unassignable = ?", true)
相关问题