Rails Foreign Key not working for one habtm relation? -
my model looks like:
class location < activerecord::base attr_accessible :title has_and_belongs_to_many :adjacent_locations, :class_name => "location", :foreign_key => "adjacent_location_id", :join_table => "adjacent_locations_locations" has_many :npcs #who in location has_and_belongs_to_many :expected_npcs, :class_name => "npc" #who expect here (is house?) has_and_belongs_to_many :items #what have? has_and_belongs_to_many :expected_items, :class_name => "item" has_and_belongs_to_many :expected_item_types, :class_name => "itemtype", :foreign_key => "e_item_type_id", :join_table => "e_item_types_locations" end every single 1 of has_and_belongs_to_many works except "expected_item_types".
it looks adjacent locations in model, not work.
my migration runs fine, , looks other join tables far can tell:
class createeitemtypeslocationstable < activerecord::migration def self.up create_table :e_item_types_locations, :id => false |t| t.references :e_item_type t.references :location end add_index :e_item_types_locations, [:e_item_type_id, :location_id], :name => "eit_loc" end def self.down drop_table :e_item_types_locations end end it has named index expected_items does, , foreign key in model location does. there special when setting foreign key named index?
the actual error i'm getting
sqlite3::sqlexception: no such column: e_item_types_locations.item_type_id: select "item_types".* "item_types" inner join "e_item_types_locations" on "item_types"."id" = "e_item_types_locations"."item_type_id" "e_item_types_locations"."e_item_type_id" = 1 which implies it's ignoring foreign key set... there wrong this?
edit: think figured out @ least part of it, instead of foreign key, should "association_foreign_key". but...then...why didn't have adjacent_locations? because of same class model in?
looks needed "association_foreign_key" instead of "foreign_key" expected_item_types field. know why didn't need "adjacent_locations" field?
Comments
Post a Comment