Thread: [SQLObject] object has no attribute
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: MJR <py...@ce...> - 2004-08-30 10:30:25
|
Any idea why the one-to-many example from SQLObject documentation works with addresses=MultipleJoin('Address'), but doesn't with addr=MultipleJoin('Address'). I am using a version from SVN. tx, mike +++++++++++++++++++++++++++++++++++++++++++++++++++ Traceback (most recent call last): File "C:\wroot\mps\tracker\test.py", line 26, in ? print p.addr AttributeError: 'Person' object has no attribute 'addr' +++++++++++++++++++++++++++++++++++++++++++++++++++ from sqlobject import * __connection__ = 'mysql://test@localhost/test' class Person(SQLObject): firstName = StringCol() middleInitial = StringCol(length=1, default=None) lastName = StringCol() addr = MultipleJoin('Address') class Address(SQLObject): street = StringCol() city = StringCol() state = StringCol(length=2) zip = StringCol(length=9) person = ForeignKey('Person') def reset(): Person.dropTable(ifExists=True) Person.createTable() Address.dropTable(ifExists=True) Address.createTable() reset() p = Person(firstName='John', lastName='Doe') print p.addr a1 = Address(street='123', city='Smallsville', state='IL', zip='50484', person=p) print [a.street for a in p.addr] +++++++++++++++++++++++++++++++++++++++++++++++++++ |
From: Ian B. <ia...@co...> - 2004-08-31 04:08:29
|
MJR wrote: > Any idea why the one-to-many example from SQLObject documentation works with > addresses=MultipleJoin('Address'), but doesn't with > addr=MultipleJoin('Address'). That seems to be a bug -- SQLObject simply ignores the attribute you use. Well, it's hard, because there's sometimes more than one method, as in RelatedJoin (with add and remove). -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |
From: Cyril E. <cy...@de...> - 2004-08-31 11:54:15
|
Ian Bicking wrote: > MJR wrote: > >> Any idea why the one-to-many example from SQLObject documentation >> works with >> addresses=MultipleJoin('Address'), but doesn't with >> addr=MultipleJoin('Address'). > > > That seems to be a bug -- SQLObject simply ignores the attribute you > use. Well, it's hard, because there's sometimes more than one method, > as in RelatedJoin (with add and remove). > Yes, I have the same problem with the svn version and take a look inside joins.py/SOMultipleJoin.__init__ method. I see that now you use the joinMethodName parameter to create the property name. I understand that but it is not very intuitive. Someone intends that the property name of created object is the one he writes in his code. Why not use this name for creating properties and methods ? Cyril Elkaim |
From: Cyril E. <cy...@de...> - 2004-08-31 12:35:04
|
Ian, The joinMethodName argument doesn't work with MultipleJoin. If I write the following: class Patient(SQLObject): teeth = MultipleJoin("Tooth", joinColumn="patientid", joinMethodName="teeth") the svn verion complains because joinMethodName receives multiple values. In fact I must comment out the parameter setting in the following method from joins.py/Join to make it work. def withClass(self, soClass): return self.baseClass(soClass=soClass, #CE joinMethodName=self._joinMethodName, **self.kw) But the better solution should be, I think, to not have to use joinMethodName at all, the property name does the trick for me. I think that it should be better to set addRemoveName instead; for example: class Patient(SQLObject): teeth = MultipleJoin("Tooth", joinColumn="patientid", addRemoveName="Tooth") ==> defining addTooth and removeTooth Cyril Elkaim |