On Apr 1, 2008, at 10:01 AM, sniffer wrote:
> > hi all, > first of all thanks for the replies to my last question,now i have a > different problem although not entirely different > i again have a two host model where the query objects from 1 host are > sent to the other host and added to the database there in.this works > fine with individual tables where the instance key is removed at the > other end then the object is added using session.merge, but if there > are query objects that also contain relations then this doesnt work as > when the instance key is removed the data in the relation collection > also vanishes.any ideas on how to tackle this. removing _instance_key is not really supported and is probably going to break in an upcoming release. Are you just trying to replicate tables ? Straight replication is better implemented without an ORM. If its a more specific use case, I'd advise adding explicit copy() methods to your instances so that you aren't relying on SA hacks to achieve what you're trying to do, i.e. if you had a class with "field1", "field2", and "some_collection", something along the lines of: class MyClass(object): def copy(self): return MyClass(field1 = self.field1, field2 = self.field2, some_collection=[c.copy() for c in self.some_collection]) a generic version might look like: class MyClass(object): def copy(self): new = MyClass() for k in dir(self): if k.startswith('_'): continue value = getattr(self, k) if isinstance(value, list): setattr(new, k, [c.copy() for c in value]) else: setattr(new, k, value) the desired SA feature here would probably be better implemented as a recipe, and would be along the lines of using the same idea as merge() to produce a function that is explicitly designed to create "clean" copies of instances. If someone wants to produce this recipe using sess.merge() as a guide, we can put it on the wiki. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---