|
I need to create a very simple web app: - A "Team" which contains main contact information - A "Participant" which contains a particular person The Team has_many participants and the participant belongs_to Team It's a simple one-to-many relationship All I really need the app to do is add those together as one step. i.e. Create a team and add the participants. So far what's stopping me is how to implement the one-to-many in Rails. Does anyone have a sample application that implements a one-to-many and has views that allow them to be created at once? Should I be combining the two above into one Model? Or should they be two separate models with a single controller?
|
# ¿ Sep 11, 2007 14:30 |
|
|
# ¿ May 8, 2024 06:09 |
|
Thanks, after quite a bit of trial and error I've got it functional. Now to make it usable with the magic of error handling and stylesheets
|
# ¿ Sep 12, 2007 05:52 |
|
Say I have the following models: Person Job With data: Person: - John - Tony - Bob And Jobs: - Driver - Shipper - Receiver - Cook When I'm creating the actual class for the model, I would have for Person: code:
Now my question is - what if each person has multiple primary Jobs and multiple secondary Jobs? How would that be expressed? Would I need to create a third model called, for example, PrimaryJob that has a Person and Job? Then another one called SecondaryJob with Person and Job indexes? I figure that would work but seems that there should be a way to do that within the Person/Job model without creating the extra model.
|
# ¿ Mar 18, 2010 04:05 |
|
skidooer posted:If jobs are unique there is no point in the added complexity of a join model. For example: John, primary jobs: driver, cook, secondary jobs: shipper Tony, primary jobs: shipper, secondary jobs: cook, receiver Bob, primary jobs: driver secondary jobs: receiver Need to the simplest way to express a many-to-many relationship multiple times that reference the same model.
|
# ¿ Mar 19, 2010 02:19 |
|
trinary posted:Read up on has_many :through and do something like what I suggested. http://blog.hasmanythrough.com/2006/4/20/many-to-many-dance-off
|
# ¿ Mar 22, 2010 13:36 |