私は再び単純なクエリで立ち往生しています。私は次のモデルを持っています
class Category < ActiveRecord::Base
has_many :item_types
has_many :items, :through => :item_types, :source => :category
end
class ItemType < ActiveRecord::Base
belongs_to :category
has_many :items
end
class Item
belongs_to :item_type
end
現在、カテゴリに分類されるすべてのアイテムをフェッチするクエリを作成しようとしています。私はこのようなクエリを書きました:
Category.joins(:item_types,:items).where("category.id=?",1)
where条件が含まれているとエラーが発生します。なぜそうなるのかわかりません。これは非常に基本的な参加だと思いましたが、自分でやることはできましたが、無駄でした。