belongs_to more than one associated record

61 views Asked by At

Sorry for this nooby question.

Reading this here : guides.rugyonrails

It says that the belongs_to association is appropriate when each book can be assigned to exactly one author. But what is the best practice if a book can have several authors?

I need a table Books and a table Authors, where Books can have 1 to 10 authors.

Thanks !

1

There are 1 answers

0
Kevin Etore On

has_many is the answer for you. So in the Book model has_many :authors and the Author model belongs_to :book. You should read has_many association rubyonrails