From ef6d2c0cf5c709c7b17945e532de21b95b53ef88 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 8 Mar 2006 21:55:33 +0000 Subject: [PATCH] added identity() method to mapper, to help get the primary key of an instance. --- lib/sqlalchemy/mapping/mapper.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py index 4b5997b38b..825d3cd755 100644 --- a/lib/sqlalchemy/mapping/mapper.py +++ b/lib/sqlalchemy/mapping/mapper.py @@ -306,11 +306,17 @@ class Mapper(object): def identity_key(self, *primary_key): + """returns the instance key for the given identity value. this is a global tracking object used by the objectstore, and is usually available off a mapped object as instance._instance_key.""" return objectstore.get_id_key(tuple(primary_key), self.class_) def instance_key(self, instance): - return self.identity_key(*[self._getattrbycolumn(instance, column) for column in self.pks_by_table[self.table]]) + """returns the instance key for the given instance. this is a global tracking object used by the objectstore, and is usually available off a mapped object as instance._instance_key.""" + return self.identity_key(*self.identity(instance)) + def identity(self, instance): + """returns the identity (list of primary key values) for the given instance. The list of values can be fed directly into the get() method as mapper.get(*key).""" + return [self._getattrbycolumn(instance, column) for column in self.pks_by_table[self.table]] + def compile(self, whereclause = None, **options): """works like select, except returns the SQL statement object without compiling or executing it""" -- 2.47.2