Composed_of vs has_one

Im trying to decide how to model very simple relationships in
ActiveRecord.

My understanding is that as far as database performance goes, using
composed_of will be easier on the database but a little ackward when
working with the object, considering it the composed_of object is frozen
is not an AR class.

With a has_one, you can include the object onto the main object using
:include, where as, with a composed of relationship, you have to use the
composed_of name to get it initialized onto the object.

I guess the main question is, how much more efficient is it to have all
the records already on the table, than to offload them to a has_one
relationship. To me it seems, like it greatly complicates the query
required to retrieve the object.

In conclusion:
has_one: use when you rarely need to include it on the main object
composed_of: use this when you almost always need this object included
with the main object.

Do you guys generally agree?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs