Ruby on rails 循环遍历对象以查找匹配项
我有一个具有以下关系的Ruby on rails 循环遍历对象以查找匹配项,ruby-on-rails,loops,rails-activerecord,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 classshifttrue) 任何帮助:) 谢谢简单,但正是我需要的:)简单,但正是我需要的:) Shift.includes(:type).where("t
Shift
和Type
表:
class Shift < ActiveRecord::Base
belongs_to :type
end
class Type < ActiveRecord::Base
has_many :shifts, :dependent => :destroy
end
classshift:销毁
结束
Type
表有一个名为Unassignable
的属性
我想执行一个查询,返回属于类型的所有移位
,其中Unassignable
属性为true
比如:
Shift.where(:Shift.type.unassignable=>true)
任何帮助:)
谢谢简单,但正是我需要的:)简单,但正是我需要的:)
Shift.includes(:type).where("types.unassignable = ?", true)