On Jun 20, 2013, at 1:43 PM, Chris Withers <[email protected]> wrote:

> Digging up an old thread, this time with (I hope) correct terminology:
> 
> If I have a transient object which has had some attributes set on it, what 
> would be the best way to use that object to load an object based on those 
> attributes from the database?
> 
> I didn't noticed a session.lookup(myobj) method ;-)


The mapper has all the identity key functions now:

from sqlalchemy import inspect

def lookup(session, obj):
    mapper = inspect(obj).mapper
    return session.query(mapper).get(mapper.primary_key_from_instance(obj))


a2 = A(id=1)
assert lookup(s, a2) is a1, "%r != %r" % (a1, a2)



-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to