Awesome, thanks for that.
On Fri, Aug 29, 2014 at 10:43 PM, Michael Bayer <mike...@zzzcomputing.com> wrote: > not a shorter way, but more correct in case you have columns mapped to > different names: > > mp1 = inspect(instance1) > mp2 = inspect(Class2) > > Class2(**dict( > > zip( > mp2.get_property_by_column(col).key for col in mp2.primary_key, > mp1.primary_key_from_instance(instance1) > ) > > )) > > > > > On Aug 27, 2014, at 9:24 PM, Gerald Thibault <dieselmach...@gmail.com> > wrote: > > # instance1 is an instance of Class1, i want to create Class2 with the > same pk > > keys = [key.name for key in class_mapper(Class2).primary_key] > cls, values = identity_key(instance=instance1) > kwargs = dict(zip(keys, values)) > instance2 = Class2(**kwargs) > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/d3mMjDLlqfY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.