Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-30 Thread JT Thibault
Awesome, thanks for that. On Fri, Aug 29, 2014 at 10:43 PM, Michael Bayer 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

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-29 Thread Michael Bayer
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,

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
Also, this might help to clarify my goal, this is my current working code that accomplishes the desired result, but with more introspection than I was hoping for. If there isn't something easier, this will work. # instance1 is an instance of Class1, i want to create Class2 with the same pk ke

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
On Wednesday, August 27, 2014 4:58:50 PM UTC-7, Michael Bayer wrote: > > > On Aug 27, 2014, at 6:17 PM, Gerald Thibault > wrote: > > > I have a pretty simple goal, so simple I probably don't even need > example code. > > > > I have 2 classes, and I want to pull the identity key from an insta

Re: [sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Michael Bayer
On Aug 27, 2014, at 6:17 PM, Gerald Thibault wrote: > I have a pretty simple goal, so simple I probably don't even need example > code. > > I have 2 classes, and I want to pull the identity key from an instance of one > class, and use the values to create an instance of the second, without >

[sqlalchemy] Creating a new instance using an identity key/pk?

2014-08-27 Thread Gerald Thibault
I have a pretty simple goal, so simple I probably don't even need example code. I have 2 classes, and I want to pull the identity key from an instance of one class, and use the values to create an instance of the second, without requiring (or introspecting) things like the PK names, FK names li