On Apr 20, 4:45 am, Christian MICHON <[email protected]>
wrote:
> Hi sequel-experts,
>
> I've been using xml serialization out (to_xml) recently following
> documentation found 
> athttp://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/XmlSe....
>
> 1 small issue found is that top markers are changed to lower-case, ie
> Album will become <album>. I can take care of post-processing this
> using nokogiri and renaming the markers on the fly.

Yes.  That is by design (it calls underscore), though I'm open to
making it configurable so that it it does not.

> What I've difficulty with is serializing back inside the db
> model/table (array_from_xml). Indeed, the following line seems to be
> like Album.all:
> Album.array_from_xml(Album.to_xml)

It is similar.  Not that Album.all does not save into the db, it pulls
data out of the db.  Album.array_from_xml(some_xml) pulls data out of
the xml.  The main difference is that Album.all returns records that
are not new (save will do an update), while the records returned by
Album.array_from_xml(some_xml) are new (save will do an insert).

> But data does not get saved in this way. I'm actually looking at this
> to be able to seed my db using xml files.

That's by design.  If you want to save the files, you'll have to loop
over the contents of the array.

> Is there a way to save in the db using array_from_xml ? I'm looking
> for a 1-liner solution if possible.

  Album.array_from_xml(some_xml).each{|x| x.save}

Note that the following will not work:

  Album.array_from_xml(Album.to_xml).each{|x| x.save}

because you'll get a duplicate primary key violation on the insert. :)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to