Taiwan Vincent
2012-Jan-06 20:07 UTC
Which association is right for books table and words table?
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Jan-06 20:11 UTC
Re: Which association is right for books table and words table?
On 6 January 2012 20:07, Taiwan Vincent <vincent.open.source.taiwan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Taiwan Vincent
2012-Jan-09 12:42 UTC
Re: Which association is right for books table and words table?
Hi Colin, I got it, many thanks. Vincent On Jan 7, 4:11 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 6 January 2012 20:07,TaiwanVincent > > <vincent.open.source.tai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.