has_one vs. belongs_to in Rails

Which to use? Consider your pets.

If I own a dog, round his neck is a tag with my name on. The tag is like the dog’s owner_id: I have_one dog, and the dog belongs_to me.

If the dog owned me, I’d have a tag round my neck with the dog’s name on. This would be crazy, but my tag would be my dog_id: the dog would have_one :person, and I’d belong_to my dog.

The question of whether to use has_one or belongs_to is a matter of database columns. If your Dogs table has an owner_id column, then Dog.belongs_to :owner. If your People table has a dog_id column then, unnatural though it is, Person.belongs_to :dog and Dog.has_one :person.

Learn to love your canine overlord :-)