]> git.decadent.org.uk Git - dak.git/commitdiff
Add the ORMObject.get() class method.
authorTorsten Werner <twerner@debian.org>
Tue, 25 Jan 2011 06:32:44 +0000 (07:32 +0100)
committerTorsten Werner <twerner@debian.org>
Tue, 25 Jan 2011 06:32:44 +0000 (07:32 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py

index fa52a9187bbc080caeaaa43919033b0435021b41..837ce8e47b39dfe270d9a70b0f9a2eeed8395a35 100755 (executable)
@@ -272,6 +272,21 @@ class ORMObject(object):
                 raise DBUpdateError(self.validation_message % \
                     (property, str(self)))
 
+    @classmethod
+    @session_wrapper
+    def get(cls, primary_key,  session = None):
+        '''
+        This is a support function that allows getting an object by its primary
+        key.
+
+        Architecture.get(3[, session])
+
+        instead of the more verbose
+
+        session.query(Architecture).get(3)
+        '''
+        return session.query(cls).get(primary_key)
+
 __all__.append('ORMObject')
 
 ################################################################################