Package daklib :: Module dbconn :: Class ORMObject
[hide private]
[frames] | no frames]

Class ORMObject

source code

ORMObject is a base class for all ORM classes mapped by SQLalchemy. All derived classes must implement the properties() method.

Instance Methods [hide private]
 
properties(self)
This method should be implemented by all derived classes and returns a list of the important properties.
source code
 
classname(self)
Returns the name of the class.
source code
 
__repr__(self)
Returns a short string representation of the object using the first element from the properties() method.
source code
 
__str__(self)
Returns a human readable form of the object using the properties() method.
source code
 
session(self)
Returns the current session that is associated with the object.
source code
 
clone(self, session=None)
Clones the current object in a new session and returns the new clone.
source code
Class Methods [hide private]
 
get(cls, primary_key, session=None)
This is a support function that allows getting an object by its primary key.
source code
Method Details [hide private]

properties(self)

source code 

This method should be implemented by all derived classes and returns a list of the important properties. The properties 'created' and 'modified' will be added automatically. A suffix '_count' should be added to properties that are lists or query objects. The most important property name should be returned as the first element in the list because it is used by repr().

get(cls, primary_key, session=None)
Class Method

source code 

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)

Decorators:
  • @session_wrapper

session(self)

source code 

Returns the current session that is associated with the object. May return None is object is in detached state.

clone(self, session=None)

source code 

Clones the current object in a new session and returns the new clone. A fresh session is created if the optional session parameter is not provided. The function will fail if a session is provided and has unflushed changes.

RATIONALE: SQLAlchemy's session is not thread safe. This method clones an existing object to allow several threads to work with their own instances of an ORMObject.

WARNING: Only persistent (committed) objects can be cloned. Changes made to the original object that are not committed yet will get lost. The session of the new object will always be rolled back to avoid resource leaks.