Complete the code to declare a has_one association in a Rails model.
class User < ApplicationRecord [1] :profile end
The has_one method declares a one-to-one association from the User model to the Profile model.
Complete the code to declare the inverse belongs_to association in the related model.
class Profile < ApplicationRecord [1] :user end
The belongs_to method declares the association from Profile back to User, indicating Profile belongs to one User.
Fix the error in the has_one declaration to specify the class name correctly.
class User < ApplicationRecord has_one :[1], class_name: 'UserProfile' end
The association name should be singular and match the related model logically. 'profile' is correct here.
Fill both blanks to complete the has_one association with dependent destroy option.
class User < ApplicationRecord [1] :profile, [2]: :destroy end
has_one declares the association, and dependent: :destroy ensures the related profile is deleted when the user is deleted.
Fill all three blanks to complete a has_one association with class name and foreign key options.
class User < ApplicationRecord [1] :profile, class_name: '[2]', foreign_key: '[3]' end
has_one declares the association. class_name specifies the related model name. foreign_key tells Rails which column links the models.