I have a half baked solution which I am not altogether thrilled with. If
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?