[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Add the ORMObject.get() class method.



Signed-off-by: Torsten Werner <twerner@debian.org>
---
 daklib/dbconn.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index fa52a91..837ce8e 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -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')
 
 ################################################################################
-- 
1.5.6.5



Reply to: