First off, I’ve done some googling and read some very informative
stuff, but I’m having an issue and I can’t figure out what I’m doing
wrong. I’ve got it working with one model, but the other one is
choking… Here’s the relevant data (and my current stuff):
player.rb:
class Player < ActiveRecord::Base
has_and_belongs_to_many :friends,
:class_name => “Player”, :association_foreign_key =>
“friend_id”, :join_table => “friends_players”
has_and_belongs_to_many :leagues,
:class_name =>
“Player”, :association_foreign_key=>“player_id”,
:join_table=>“players_leagues”
end
league.rb:
class League < ActiveRecord::Base
has_many :players,
:class_name => “Player”, :association_foreign_key =>
“player_id”, :join_table => “players_leagues”
end
players.yml:
user1:
name: Jason
network_id: dbg_12345
friends: user2, user3
user2:
name: Shane
network_id: dbg_12346
friends: user3
user3:
name: Dan
network_id: dbg_12347
friends: user1
leagues.yml:
league1:
player_id: user1
players: user1, user2, user3
Now when I attempt to use my custom rake task to import the fixtures,
I get:
rake aborted!
Mysql::Error: #42S22Unknown column ‘players’ in ‘field list’: INSERT
INTO leagu es
(players
, player_id
) VALUES (‘user1, user2, user3’, ‘user1’)
So, it’s not quite working, and I’m not sure why. League is actually
supposed to be owned by a player (it has a player_id) field, but I’ve
been experimenting trying to get it working.