How would you implement a has_n association on Rails for a given n? Let’s say for example a rugby team. It has 15 players. Would you implement it as has_many and check in before save to make sure it has 15 players, or would you prefer to implement it as 15 belongs_to? Note that the order is important in this case.
How would you implement a has_n association on Rails for a given n ?
Share
Edited to reflect your request for ordering…
You’ll need to add a sort_key to the players table. You can use an integer, but a float is always a more flexible choice. Then use the
:order => "sort_key"phrase.