Forum: Ruby on Rails Need help with a complicated use of composed_of()

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5a8dfcbdf0ab9b87d1299ad228e4af2b?d=identicon&s=25 Chad Thatcher (Guest)
on 2007-02-10 14:06
(Received via mailing list)
I am using composed_of() in a model that maps a complex data structure
(simply stored in a blob field in the table) to a custom class.  Like

*class* Master < ActiveRecord::Base

  composed_of *:marc*, *:class_name* => "Marc", *:mapping* => %w(source)


*class* Marc

 include Comparable



This works beautifully so far in both directions (loading up from the db
and saving to the db).  I am now faced with a particularly difficult

In this complex data structure I would like to store values that map
back to other tables in the database.  For example, one of the elements
of the data structure refers to a person.  I have a standard People
model with all the bells and whistles.  When I unravel the complex data
structure (in Marc class) I want to lookup people from the people table
primarily for data integrity purposes. For this purpose I can store the
primary ids of people records in the data structure.  Furthermore, when
the user comes to edit this data structure (in a ludicrously complicated
data entry form) I want them to be able to lookup values from the people
table in order to select and insert into this data structure.

There are several occurrences of people throughout the data structure so
it would be wasteful to perform separate lookups as show.rhtml or
edit.rhtml come across them.  I have a way of asking the custom class
(Marc) to fetch all these "foreign keys" from the data structure before
I start building the form and, hence, do one big fetch.

My first question is this:  is there a way I can use the usual
ActiveRecord mechanism to manage this or do I need to manage the
satellite tables (People) directly in Marc class.  That is if I had Marc
class inherit from ActiveRecord::??? like standard models (even though
Marc is not a whole table or standard model unto itself) would this be
completely illogical?  I ask this because it would be nice to take
advantage of some of the mechanisms in ActiveRecord without actually
being an ActiveRecord if you get my drift.

I see the current setup as:

Master (db table) --> Marc (custom, non-db) --> People (db table)

And lastly - is this the best way of dealing with this type of setup?  I
would like to hear opinions from people on other possible approaches
bearing in mind that the data structure (handled by Marc class) is
incredibly complex and cannot be stored in a normalised form in the

Apologies for such a long post, and kind regards,

Chad Thatcher.
This topic is locked and can not be replied to.