I got two tables, books and words.

A book has many words.

However a work is not belong to a book, because a word can be used in
different book.

Which association is right for this case?

Many thanks for reply.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Jan 6, 2012 at 8:12 pm

    On 6 January 2012 20:07, Taiwan Vincent wrote:
    I got two tables, books and words.

    A book has many words.

    However a work is not belong to a book, because a word can be used in
    different book.

    Which association is right for this case?
    has_and_belongs_to_many

    or use an explicit join table and has_many :through.

    See the Rails Guide on ActiveRecord Associations for the basics of
    using various associations.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Taiwan Vincent at Jan 9, 2012 at 12:43 pm
    Hi Colin,

    I got it, many thanks.

    Vincent
    On Jan 7, 4:11 am, Colin Law wrote:
    On 6 January 2012 20:07,TaiwanVincent

    wrote:
    I got two tables, books and words.
    A book has many words.
    However a work is not belong to a book, because a word can be used in
    different book.
    Which association is right for this case?
    has_and_belongs_to_many

    or use an explicit join table and has_many :through.

    See the Rails Guide on ActiveRecord Associations for the basics of
    using various associations.

    Colin
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 6, '12 at 8:08p
activeJan 9, '12 at 12:43p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Taiwan Vincent: 2 posts Colin Law: 1 post

People

Translate

site design / logo © 2021 Grokbase