[SQLObject] Inheritance forgets ForeignKey
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Craig <cr...@re...> - 2006-08-24 09:16:27
|
Hi, Is this a bug? I'd like to use the form: print student.contactID instead of : print student.contact.id cause I suspect its better optimized. Thanks -----------------------------code snip------------- from sqlobject import * from sqlobject.inheritance import InheritableSQLObject connectString = 'postgres://myuser:mypass@Localhost/mydb' connection = connectionForURI(connectString) sqlhub.threadConnection = connection class Contact(SQLObject): number = StringCol() class Role1(InheritableSQLObject): department = StringCol() contact = ForeignKey('Contact', notNone=True) class Student(Role1): year = IntCol() Student.dropTable(ifExists=True) Role1.dropTable(ifExists=True) Contact.dropTable(ifExists=True) Contact.createTable() Role1.createTable() Student.createTable() contact = Contact(number="555-90210") student = Student(department="physics", year=1, contact=contact) print student.contact print student.contact.id print student.contactID -----------------------------code snip------------- That produces this issue: -----------------------------result snip------------- <Contact 1L number='555-90210'> Traceback (most recent call last): File "sqlobjectInheritance.py", line 32, in ? print student.contactID File "<string>", line 1, in <lambda> File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 984, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Student' object has no attribute '_SO_val_contactID' -----------------------------result snip------------- I reproduced the fact with both these versions of sqlobject: sqlobject 0.7.0 and sqlobject 0.7.1b1 |