画像は私のデータモデルの一部を示しています。ユーザーに関連付けられているすべてのアイテムを(組織およびitems_groupを介して)フェッチしたいと思います。モデルを変更して、このクエリをコントローラーに書き込むにはどうすればよいですか?:through =>組織を使用すると、すべてのitems_groupsを取得できますが、クエリ関連アイテムにもう1つのリレーションを含める方法はありません。
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