I managed to solve one issue that I was encountering wherein
deserializing serialized XML model instances with multiple
associations of varying types, specifically, many_to_many
associations, would cause duplicate primary key errors.

The problem was being caused by an association that was being included
in the to_xml parameters.  I needed that association to get recreated
when pulling in the entity from the XML.

However, the included association entities were composed of nothing
but fields with unique constraints on them.  That meant that if I
pulled in the associated entities, I would have to delete the entities
the deserialized entities would be replacing.  Unfortunately, those
entities were part of a many-to-many relationship.  Other entities in
the database relied on the existence of those associated entities.  I
couldn't just go in and delete them so that I could pull in this one
parent entity.

To solve this, I had to add a one-to-many association on the main
entity model class so that I could access the join table as a list.
This way, when I deleted the association through a cascade delete to
make room for the freshly deserialized parent entity, I would then be
able to deserialize just the association information that linked the
already existing associated entities to the parent entity.

I wish there was a way to specify that to_xml only serialize a many-to-
many association as associative information, instead of including the
actual associated entities in the serialization, without marking up my
model classes with irrelevant one-to-many associations for that join
table association info.

-- 
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