[SQLObject] Re: Strange bug with SQLObject 0.6
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Carlos R. <car...@gm...> - 2004-10-18 12:50:55
|
I've found my 'bug', and it hasn't nothing to do with naming conventions. It was a mistake of mine: my one-to-many relationship used a different column name from the default one, and I was not aware that in this case I had to supply a joinedColumn parameter (in fact, another user pointed it out to me, but I misunderstood his point, and assumed that I just had to upgrade my SQLObject installation). Regarding this problem, I have a suggestion: add a remark on the "One-to-Many Relationships" section of the documentation. The relevant information does exist but it's buried down in the MultipleJoin reference; so when I replayed the example provided in the tutorial section it worked, but I was not aware of the option, until I read the reference. For example, something like this: http://www.sqlobject.org/docs/SQLObject.html: """ We get the backreference with addresses = MultipleJoin('Address'). When we access a person's addresses attribute, we will get back a list of all the Address objects associated with that person. An example: p = Person(firstName='John', lastName='Doe') print p.addresses #>> [] a1 = Address(street='123', city='Smallsville', state='IL', zip='50484', person=p) print [a.street for a in p.addresses] #>> ['123'] In this case, the relationship between the 'Person' entity and the 'Address.person' ForeignKey() column is detected and created with no need for any extra information -- the name is mapped automatically. However, if the name of the ForeignKey() column is different from the entity name which it relates with, a joinedColumn argument will be required. For example: <...> """ I found my mistake only after realizing that the join method had no other way to find the joined-to column :-) But it's easy to overlook it, because SQLObject abstracts very well from these 'implementation details'. That's why I believe a comment early in the documentation (or in a FAQ section) could be useful. -- Carlos Ribeiro Consultoria em Projetos blog: http://rascunhosrotos.blogspot.com blog: http://pythonnotes.blogspot.com mail: car...@gm... mail: car...@ya... |