Re: [SQLObject] SQLObject Class-wide where-condition
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2008-02-14 19:49:49
|
On Thu, Feb 14, 2008 at 08:01:45PM +0100, Frank Wagner wrote: > class Reisen(SQLObject): > class sqlmeta: > #some things > pass > > @classmethod > def select(cls, clause=None, **kw): > """docstring for _get_BUCHUNGEN""" > sresult = SQLObject.select(clause, **kw) > return sresult.filter(~ LIKE(Reisen.q.REISENR, "BUS%")) > > Reisen.select(...) leads to an error: > AttributeError: No connection has been defined for this thread or process I see. The problem is that there is a connection for the class Reisen, but the connection is not passed to SQLObject.select(), because the "cls" parameter is this case is SQLObject, not Reisen, and there is no connection for SQLObject. I see two ways to fix this. Either: sresult = SQLObject.select(clause, connection=cls._connection, **kw) or sresult = super(Reisen, cls).select(clause, **kw) In the first case you pass the connection explicitly, in the second case you pass Reisen as the "cls" argument to the the Reisen's parent (SQLObject) .select(). Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |