SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Confused about correct model relationship

    Hi,

    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.
    Thanks

  2. #2
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I solved this myself with a little help from google and a lot from a tutorial...
    #5 from http://www.softiesonrails.com/search?q=forms+in+rails is what did it for me.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •