我试图在关于铁路项目的鲁比项目中做以下工作:
class FoodItem < ActiveRecord::Base
has_and_belongs_to_many :food_categories
has_many :places, :through => :food_categories
end
class FoodCategory < ActiveRecord::Base
has_and_belongs_to_many :food_items
belongs_to :place
end
class Place < ActiveRecord::Base
has_many :food_categories
has_many :food_items, :through => :food_category
end
但称之为“试样方法”some_food_item.places
。 我有以下错误:
ActiveRecord::StatementInvalid: PGError: ERROR: column
food_categories.food_item_id does not exist
LINE 1: ...laces".id = "food_categories".place_id WHERE (("food_cate...
: SELECT "places".* FROM "places" INNER JOIN "food_categories" ON "places".id = "food_categories".place_id WHERE (("food_categories".food_item_id = 1))
什么是完美的,因为关于粮食电离层和食品箱的HABTMs I有名为的食品分类——食品——项目代码>的制图表。
我必须做些什么才能通过制图表正确检查位置,而不是在<食品-类别编码>表中寻找<食品>项目_id?