Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 循环遍历对象以查找匹配项_Ruby On Rails_Loops_Rails Activerecord - Fatal编程技术网

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)