Hi,

I have a team which has and belongs to many players.

class Team < ActiveRecord::Base
  has_and_belongs_to_many :players
end

class Player < ActiveRecord::Base
  has_and_belongs_to_many :teams
end

What I'd like to do is add bench players to my team.  The bench will
have many players and many players can be on the bench.

I tried to do it like this:

class Team < ActiveRecord::Base
  has_and_belongs_to_many :players
  has_and_belongs_to_many :bench_players, :class => 'Player'
end

I made the association table like this:

class TeamsBenchPlayers < ActiveRecord::Migration
  def self.up
    create_table :teams_bench_players, :id => false do |t|
      t.column :team_id, :integer, :null => false
      t.column :player_id, :integer, :null => false
    end
    add_index :teams_bench_players, [:team_id]
    add_index :teams_bench_players, [:player_id]
  end
  def self.down
    drop_table :teams_bench_players
  end
end

However when I do this:

team.bench_players << player

It saves it in the wrong table, i.e. the team_players table.  What am
I doing wrong?

Thanks,
Frank

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to