GFunk... / gmail.com wrote:
> Jamey Cribbs wrote:
> > GFunk913 / gmail.com wrote:
> > > # Create new table.  Notice how you specify whether a column is indexed
> > > or not.
> > > db.create_table(:thing) do |tbl|
> > >   tbl.add_column(:foo,:dunno_what_to_put)
> > > end
> > >
> > > # Add a record.  You can also use #create.
> > > rec = Thing.new
> > > rec.foo = (1..100).to_a
> > > rec.save
> > >
> > > puts Thing.find.first.foo.size    #100
> > >
> > >
> > Logan already gave you one way to do this, and, probably from a purely
> > relational perspective, his suggestion is the right way to do it.
> >
> > Additionally, I know that ActiveRecord has the serialize class method
> > that you can use to have the object specified Marshaled into and out of
> > the db.  I am thinking of supporting that method, just because I want to
> > stay close to ActiveRecord's api.  The funny thing is, Mongoose
> > *already* Marhsals all of the data (that's how it stores the table
> > records).  Right now, I don't think I am doing much data checking in the
> > #save method, so you could probably get away with declaring the data
> > type as :string and then just going ahead and saving the array to
> > rec.foo like you are doing in the example.  It should work.
> >
> > Of course, in an upcoming version, I will make all of this work the way
> > it should, i.e. do more data type checking in #save and also give you
> > the ability to specify which columns you want to serialize.
> >
> > HTH,
> >
> > Jamey
>
> Yup, I understand i could relational-ize the array, it was a bad
> example.  Pretend i said an instance of some arbitrary Foo class
> instead of an array.  the point is I want to serialize arbitrary data,
> taking advantage of marshaling.
>
> I tried the :string method.  I get a dump format error when trying to
> read it back out of the found record.
>
> I'm familiar with  the serialize functionality in activerecord, that's
> the basic idea.  I think the problem is basically that the proper
> escaping for storing dump strings isn't being done.  I'll try and see
> if I can hack something in to make this work.

The AR serialize method does some serializing via YAML.  From the docs:

Specifies that the attribute by the name of attr_name should be
serialized before saving to the database and unserialized after loading
from the database. The serialization is done through YAML.

I don't know if that would be my prefered way of handling it.  I'm
using this functionality in an app presently and it works fine, but it
seems uneccesary to me (unless I'm missing something, which is
certainly possible).