Complete the code to declare a has_many relationship in a Rails model.
class Author < ApplicationRecord [1] :books end
The has_many method declares a one-to-many relationship from Author to Book models.
Complete the code to define the inverse belongs_to relationship in the associated model.
class Book < ApplicationRecord [1] :author end
The belongs_to method sets the many-to-one side of the relationship from Book to Author.
Fix the error in the has_many declaration to specify dependent destroy behavior.
class Author < ApplicationRecord has_many :books, [1]: :destroy end
The dependent: :destroy option ensures that when an author is deleted, their books are also deleted.
Fill both blanks to create a has_many through association between Author and Genre through BookGenre.
class Author < ApplicationRecord has_many :book_genres has_many :[1], through: :[2] end
The has_many :genres, through: :book_genres sets up a many-to-many relationship through the join model BookGenre.
Fill all three blanks to define a has_many association with a custom foreign key and class name.
class User < ApplicationRecord has_many :[1], foreign_key: '[2]', class_name: '[3]' end
This code defines a has_many association named authored_books that uses author_id as the foreign key and points to the Book model.
