我再次陷入一個簡單的查詢。我有以下型號帶條件的多個連接3.2.7
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)
它其中包含的條件時,拋出了我的錯誤。我不知道爲什麼會這樣做。我認爲這是一個非常基本的聯合,我可以自己做,但徒勞無功。
,你能否告訴我們錯誤信息? – MurifoX