Ruby-on-rails – Rails: belongs_to vs has_one

associationsbelongs-tohas-manymodelruby-on-rails

A bit of a newbie question on rails associations.

I have a Bug model, and a Status model. Status is basically just a key/value pair table. Out of the choices available, I would say Bug has_one Status makes the most sense. However, according to this

Content belongs_to ContentTemplate. Go
back and look at how I described the
problem, and you'll see that it works.
With belongs_to, the table accepts
responsibility for the foreign key. So
Content has a content_template_id. And
ContentTemplate doesn't need anything.
I can point to it at will. Done.

Bug belongs_to Status would be more appropriate (since Bug should take the foreign key). Semantically, his example makes sense, but mine makes none. Is this just a quirk of rails where in this situation it looks odd, or am I not understanding something/doing it wrong?

Best Answer

Yes, I think you've just found a slightly odd-looking scenario in Rails. I suppose it might be useful to view "status" as a sort of category to which the bug belongs — in that light, it makes sense.

Related Topic