Hi, I was wondering if there is an easy way to copy SQLA objects from one DB to another. I've poked around and found this thread: http://groups.google.com/group/sqlalchemy/browse_thread/thread/c1bd8cfe862441d6 but my application is different so I thought I'd post.
Basically, I have a database of many SQLA objects, call them Users. Each user has foreign key references to addresses, groups, etc. I want to create a new test database which contains a small subset of Users, but pulls any addresses, or groups over as well and creates rows in those tables to satisfy the foreign key constraints. I don't care if primary keys change (as long as the constraints are satisfied). To copy over the first 10 users I naively tried doing something along the lines of: sess1 = ProductionDBSession() sess2 = TestDBSession() users = sess1.query(User).filter(User.id<10) for user in users: sess2.add(user) sess2.commit() Of course this doesn't work because user is in the persisted state within sess1. What I was hoping though, was that the user.address_list and user.group_list attributes would also be copied over by creating rows in the address and group tables as well as the user table and setting the proper foreign key relationships. I'm prepared to write a more custom script that copies individual objects and sets up the foreign key relationships by hand, but if there was something like this I could do to make it a simpler process, that would be great. Thanks! Sam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---