该图显示了我的数据模型的一部分。我想获取与用户关联的所有项目(通过组织和items_group)。我应该如何更改模型并在控制器中写入此查询?使用:通过=>组织我可以得到所有items_groups,但我不知道如何包括一个关系查询相关项目。通过多个表获取记录
class User < ActiveRecord::Base
has_and_belongs_to_many :organizations
has_many :items_groups, :through => :organizations
end
class Organization < ActiveRecord::Base
has_and_belongs_to_many :users
has_and_belongs_to_many :items_groups
has_many :items, :through => :items_groups
end
class ItemsGroup < ActiveRecord::Base
has_many :items, :inverse_of => :items_group
has_and_belongs_to_many :organizations
has_many :users, :through => :organizations
end
工作!非常感谢... – migu