Results 1 to 2 of 2
Aug 24, 2009, 12:08 #1
- Join Date
- Jun 2008
- 0 Post(s)
- 0 Thread(s)
Confused about correct model relationship
Taking the example of Shovell from the Simply Rails book of Stories, I want to add a finite set of categories and formats for the stories. For example, upon entering a story, maybe I want to categorize it as a Technology tutorial, and set it's format (that of the linking site) to Video. Maybe I'd have 10 predefined categories to choose from and a few formats.
In my mind I see the stories as belonging to the categories and the Formats
format has_many stories >>> stories belongs_to format
category has_many stories ... stories belongs_to category
(one category and format for each story and many stories for each category and format -- this makes sense)
I would want to assign the category and format when creating a story though, but all of the tutorials and references for multi-model forms refer to child models of the main model, rather than parent models. (example, Ryan Bates' build.tasks.stories)
On the other hand, I could just add these category, and format parameters as columns in the stories table, but that seems wrong).
I could also just make them children and switch it around to:
stories has_one category >>> category belongs_to story
stories has_one format >>> format belongs_to stories
But again, that just doesn't jive with my rationale.
And of course the point is to be able to not only enter all this in one form entry but to then filter the searches and get all the stories of a certain category that represent a specific format... and to me that just seems like the first setup I mentioned.
Which is right? If it's the first with stories as the child, how do I set it up in the form?
Any insight would be greatly appreciated.