Re: [SQLObject] Inheritance looses column
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2009-09-06 22:48:52
|
On Mon, Sep 07, 2009 at 02:10:42AM +0400, Oleg Broytmann wrote: > Aha, now I see. I got the exception for the second time. 'name' is in > dir(self) because it came from the class, but it's not in self.__dict__. > Seems like a bug. Well, got it. Not a bug in SQLObject, but a "bug" in your expectations. :) Let' see. 1/Select : SELECT a.id, a.child_name FROM a WHERE ((a.child_name) = ('B')) 1/QueryR : SELECT a.id, a.child_name FROM a WHERE ((a.child_name) = ('B')) 1/Select children of the class B: SELECT b.id, b.name, b.child_name FROM b WHERE ((b.id) IN (1, 2, 3)) 1/QueryR : SELECT b.id, b.name, b.child_name FROM b WHERE ((b.id) IN (1, 2, 3)) <class '__main__.A'> <class '__main__.B'> X 2/QueryOne: SELECT child_name FROM c WHERE ((c.id) = (1)) 2/QueryR : SELECT child_name FROM c WHERE ((c.id) = (1)) 2/COMMIT : auto <class '__main__.C'> Traceback (most recent call last): ... You see - SQLObject SELECTs data for the class C. But the table for the class is empty, 'name' is in class B. During _init() the class is not yet fully drawn from the database, so there is no 'name' in it yet. Let's wait and see if SQLObject SELECTs the additional data for the class C from the tables for its parent classes. Let's comment out your getattr (and replace it with 'pass'): 1/Select : SELECT a.id, a.child_name FROM a WHERE ((a.child_name) = ('B')) 1/QueryR : SELECT a.id, a.child_name FROM a WHERE ((a.child_name) = ('B')) 1/Select children of the class B: SELECT b.id, b.name, b.child_name FROM b WHERE ((b.id) = (1)) 1/QueryR : SELECT b.id, b.name, b.child_name FROM b WHERE ((b.id) = (1)) <class '__main__.A'> <class '__main__.B'> 2/QueryOne: SELECT child_name FROM c WHERE ((c.id) = (1)) 2/QueryR : SELECT child_name FROM c WHERE ((c.id) = (1)) 2/COMMIT : auto <class '__main__.C'> 1/COMMIT : auto [<C 1 name='X'>] Now, much later after _init(), the instance of class C got the attribute 'name'. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |