What is the difference between a belongs_to and a has_one?
Reading the Ruby on Rails guide hasn't helped me.
What is the difference between a belongs_to and a has_one?
Reading the Ruby on Rails guide hasn't helped me.
has_one
other class contains the foreign key.belongs_to
current class contains the foreign key.From a simplicity standpoint, belongs_to is better than has_one because in has_one, you would have to add the following constraints to the model and table that has the foreign key to enforce the has_one relationship:
validates :foreign_key, presence: true, uniqueness: true