...

/

Quiz Yourself: Product Model

Quiz Yourself: Product Model

Test your knowledge about the Product model.

We'll cover the following...
Technical Quiz
1.

How do we remove all associated user’s products when a user is removed?

A.

Add dependent: :destroy on products association.

# ...
class User < ApplicationRecord
# ...
has_many :products, dependent: :destroy
end
B.

Add dependent: :nullify on products association.

# ...
class User < ApplicationRecord
# ...
has_many :products, dependent: :nullify
end
C.

We only specify products association. Active Record handles it implicitly.

# ...
class User < ApplicationRecord
# ...
has_many :products
end

1 / 4