[SQLObject] Re: SQLObject inheritance patch 2
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Oleg B. <ph...@ph...> - 2004-02-12 14:40:17
|
On Thu, Feb 12, 2004 at 08:51:06AM -0500, Daniel Savard wrote:
> I sent you a little test (your test with very smalls modifications)
> and the complete SQLObject.py file patched with my patch.
Your SQLObject.py is exactly like my - byte to byte. No difference.
> It is not needed to create and drop table each time. Only to be
> sure they are created.
> Can you try it and tell me if its works now ?
Your test works ok. But the following program does not:
import SQLObject
db_conn = SQLObject.PostgresConnection(db = 'test')
class Woman(SQLObject.SQLObject):
_inheritable = 1
_connection = db_conn
name = SQLObject.StringCol()
class Wilma(Woman):
smile = SQLObject.IntCol()
woman = Woman(1)
print woman # prints <Wilma 1 childName=None smile=1>, ok
print woman.smile # => 1
print woman.name
Output:
<Wilma 1 childName=None smile=1>
1
Traceback (most recent call last):
File "w2", line 15, in ?
print woman.name
File "<string>", line 1, in <lambda>
AttributeError: 'Wilma' object has no attribute '_parent'
> As for assigning the _parent variable only in new, it is needed
> because we must link to the true instance of the parent class at this
> time to be able to get the good properties.
Aha, I see the problem now. Your patch works only when a program
creates a new object. Than the class got _parent attribute. If the
program does not calls new() - oops, attribute error.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|