From: Torsten Werner Date: Tue, 25 Jan 2011 06:32:44 +0000 (+0100) Subject: Add the ORMObject.get() class method. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b114f8978208938ea05cf2e3c69e84740cedb831;p=dak Add the ORMObject.get() class method. Signed-off-by: Torsten Werner --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index fa52a918..837ce8e4 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') ################################################################################