]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added identity() method to mapper, to help get the primary key of an instance.
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Mar 2006 21:55:33 +0000 (21:55 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Mar 2006 21:55:33 +0000 (21:55 +0000)
lib/sqlalchemy/mapping/mapper.py

index 4b5997b38b5d04430c3a268f4a887f1e96557484..825d3cd755e3f11a91ecad442a4cef271488b242 100644 (file)
@@ -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"""