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 -- Julien Cigar Belgian Biodiversity Platform http://www.biodiversity.be Université Libre de Bruxelles (ULB) Campus de la Plaine CP 257 Bâtiment NO, Bureau 4 N4 115C (Niveau 4) Boulevard du Triomphe, entrée ULB 2 B-1050 Bruxelles Mail: jci...@ulb.ac.be @biobel: http://biobel.biodiversity.be/person/show/471 Tel : 02 650 57 52 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---