From: GFunk913@... Date: 2006-07-28T14:35:06+09:00 Subject: Re: Mongoose 0.2.5 - The "Two Steps Forward, One Step Back" release GFunk913@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. FYI, from what I can tell, at least for the array (1..9).to_a, writing the marshal dump to mongoose and them reading it back makes 2 changes 1. adds a \r where the string contains a \n 2. removes a trailer \016 (shift out) This is what causes the dump format error