Having trouble trying to set a composed_of property

Hi, I followed the recipe and agile docs on using composed_of and got it
working beautifully with dummy records I inserted into the database.

I then wrote an data import script which I am running with
./script/runner and have run into trouble trying to set this column.
Here is my model:

class Master < ActiveRecord::Base
composed_of :marc, :class_name => “Marc”, :mapping => %w(source)

And now here is a snip from my import script:

marc = Marc.new(import_buffer)
master = Master.new
master.title = “a title”

master.marc = marc

I get an error on the line “master.marc = marc” and here is what it

`remove_const’: cannot remove Object::QueryParser (NameError)

If anyone can just point me in the right direction as to what I am doing
wrong I would very much appreciate it. Thanks.

I have a half baked solution which I am not altogether thrilled with. If
I change:

master.marc = marc


master.source = marc.to_s

Where ‘source’ is a text field name in the table and marc.to_s creates a
stringified form of the data structure, it all works fine. But this
goes against the examples in the recipes and agile book which represent
a purer OO approach. It means that code outside of the model needs to
be aware that this transformation needs to take place, instead of just
assigning a new Marc object to the property and saving the record. I’m
a little confused why this should be the case when other people have
managed just fine with the examples.

Could it be something to do with my Marc class definition? I can
include the source if needed.

I am also beginning to question whether or not my using composed_of() in
this case is actually the most suitable solution. So here is a
breakdown of what I needed that warranted using this:

Masters table in the database stores marc records - one marc record per
database row. Marc 21 and Micro Marc are pretty ancient data formats
used by libraries, archives, museums etc. Marc is hierarchic in nature
and each marc record represents a huge amount of data, which, when you
try to normalise it into relational database tables just becomes way too
cumbersome. As an example on a recent project I worked on where the
decision was taken to normalise into a database there were around 45,000
marc records and 2.2 million rows in mysql representing that. Just way
too cumbersome and impractical.

So I decided to keep the marc records in tact, and store the entirety of
each marc record in a single table row (in a text field). So the Marc
class is passed the entire marc record and expands it into a usable
structure. Marc#to_s pushes the marc record back into a string format
for storage in the database.

So far, tests have proved this works well and I am using a ferret index
for searches through the marc records and have mapped a handful of
important marc fields directly to table columns for quick access in SQL.

So, that is why I chose to use composed_of() and it seemed the most
appropriate - was I correct in my thinking?