Hi Ar,
The attribute idea makes a lot of sense. If I did it that way then I
could use the same join table. However I would have to use specify
custom SQL for how to select from it, right? Or is there a better
way?
-Frank
Hi Ar,
The attribute idea makes a lot of sense. If I did it that way then I
could use the same join table. However I would have to use specify
custom SQL for how to select from it, right? Or is there a better
way?
You could just have "benched" be a boolean field in the database. If
it's true, the player's on the bench. If it's false, he's on the field.
Then you can do this:
player = Player.find_by_last_name "Ronaldo"
player.benched = true # Be a team player, Ronaldo!
Not sure if has_and_belongs_to_many is exactly right (can a player be
on more than one team?) but one option is to add :conditions to the
declarations:
(not sure if this is 100% of what you need, but you get the idea)
On the other hand, if a player really can only be on one team, you'll
have a much better time if you switch back to a plain has_many. On the
other hand, if you've got a situation where players *can* be on
multiple teams, it's possible that they could be "benched" only on
some of them; in that case, you'll want a "decorated join model", with
has_many :through.
Hi Ar,
Actually I realized this won't work because players can be on multiple
teams and can be benched on one team but not the other. Therefore it
can't be an attribute of the player, it has to be an attribute of the
team.
Looks like I'll have to go back to my old idea.
-Frank