Quiz Yourself: Product Model
Test your knowledge about the Product model.
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
Question 1 of 40 attempted
Get hands-on with 1400+ tech skills courses.