mmh. maybe something around cascades? your 'links' are also not an asociation.
On Tuesday 16 December 2008 17:09:49 Julien Cigar wrote: > Hi svil, > > OK, I found back > http://groups.google.com/group/sqlalchemy/browse_thread/thread/c1bd >8cfe862441d6/83f3d5d6fde74b89 > > It seems that the way I planned to do it is the right way to do it > if I understood well. I added the lines 113-117 at > http://pastebin.com/f17e29b0f but it gives me an error : > > <class 'sqlalchemy.orm.exc.FlushError'>: Instance <SpeciesRegion at > 0x8f216cc> is an unsaved, pending instance and is an orphan (is not > attached to any parent 'Species' instance via that classes' > 'regions' attribute) > > Any idea ? > > Thanks, > Julien > > On Tue, 2008-12-16 at 16:10 +0200, [email protected] wrote: > > look down the group recently, there was a similar question on > > .copy(). this is more of a semantical question, because > > diff.things need be treated differently. > > - own references 1:1 - either None or copy of the referenced > > object - references m:1 - the reference itself > > - collecions 1:many) - either new empty collection or new > > collection of copies of the items > > - asociation - new collection conating links betwen new owner > > and the items. > > there may be more sematics involved, e.g. in bitemporal case all > > above are implemented as associations but are not always treated > > as such, copy-wise. and other cases. > > > > svil > > > > On Tuesday 16 December 2008 15:04:03 Julien Cigar wrote: > > > Dear SQLAlchemy users, > > > > > > I have a mapped object called "Species" with a lot of > > > relation() in it. The user wants to have a "duplicate" > > > function, so for a given "Species" a new exact copy should be > > > created, with all the relation(). > > > > > > I have pasted a copy of my code here : > > > http://pastebin.com/f3e50a4fa > > > > > > As you can see at lines 53-55 of my paste, I just iterate on > > > those relations and I use a setattr() on the new object. It > > > works perfectly, except for the "regions" relation (line 16), > > > where SQLAlchemy does UPDATE statements: it replaces the > > > "SpeciesRegion.species_id" of the source Species with the new > > > duplicated Species.id, so the source Species has no more > > > "regions" (SpeciesRegion). It seems logical to me because > > > SpeciesRegion is an association object, but I wondered if there > > > is a better way to do it than 1) iterate of SpeciesRegion > > > objects of the source Species, 2) create a new SpeciesRegion, > > > 3) Adapting SpeciesRegion.region 4) add the new SpeciesRegion > > > to the new Species.regions ? > > > > > > Thanks, > > > Julien --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
