On Fri, Oct 23, 2009 at 12:40 PM, Joril <jor...@gmail.com> wrote: > > Hi everyone! > I'm trying to automatically build a shallow copy of a SA-mapped > object.. At the moment my function is just: > > newobj = src.__class__() > for prop in class_mapper(src.__class__).iterate_properties: > setattr(newobj, prop.key, getattr(src, prop.key)) > > but I'm having troubles with lazy relations... Obviously getattr > triggers the lazy loading, but since I don't need their values right > away, I'd like to just copy the "this should be lazy loaded"-state of > the attribute... Is this possible? > > Many thanks for your time! >
I did something similar. I iterated on class_mapper().columns to get the attributes to populate. That approach skipped all the relations, and in my case was exactly what I wanted Something like this (untested): newobj = src.__class__() for col in object_mapper(src).columns: setattr(newobj, col.name, getattr(src, col.name)) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---