11.13.07
ActiveRecord has_one versus belongs_to (finally understood)
I spent some time googling for an answer to the question I’ve had about when to use has_one or belongs_to. I came across Duane’s blog where he addressed this exact issue.
Ultimately the phrase that made it sink in was:
“With belongs_to, the table accepts responsibility for the foreign key. With has_one, the table expect the other table to hold it.” (which he attributes to this wiki).
The main shift is that I need to stop thinking in terms of the foreign keys and not the containing objects.
So thanks, Duane.
Duane said,
November 14, 2007 at 7:18 am
You’re welcome.