bir has_and_belongs_to_many dernek aracılığıyla:Has_many: Ben bir Ruby on Rails projede aşağıdaki yapmaya çalışıyorum
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
Ama örnek yöntemi some_food_item.places
çağırarak bana aşağıdaki hatayı veriyor:
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))
Hangi Mükemmel bir anlam ifade eder - FoodItem ve FoodCategory'deki HABTM'ler nedeniyle food_categories_food_items
isimli haritalama tablosuna sahibim.
food_categories
tablosunda food_item_id
ürününü aramak yerine, eşleme tablosundan doğru bir şekilde yerlere bakmak için some_food_item.places
almak için ne yapmalıyım?
Kesinlikle yardımcı olur! Hem çözüm için hem de HABTM'deki kafalar için teşekkür ederiz. Eminim bu çözümü uygulayacağım tek yer olmayacak! –