SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    confused about relationships

    How would I express the following with relationships:
    I have an "articles" table, an "authors" table, a "collections" table, and an "articles_collections" table.
    An "article" has a reference to an "author_id".

    Here is what I have, but not sure it's correct:

    PHP Code:
      class Collection ActiveRecord::Base
              has_and_belongs_to_many 
    :articles
      
      
    class Author ActiveRecord::Base
          has_many 
    :articles
      
      
    class Article ActiveRecord::Base
          belongs_to 
    :author
          has_and_belongs_to_many 
    :collections 
    Thanks for any help or suggestions.
    Last edited by MikeShank; Jul 1, 2006 at 18:57.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct!

    That is, if your articles table has an author_id, and not the other way around.

  3. #3
    SitePoint Zealot
    Join Date
    May 2001
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks


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
  •