Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Alex Le Dain <alex <at> psi.com.au>
Subject: ForeignKey Column Name Limitation
Newsgroups: gmane.comp.python.sqlobject
Date: Tuesday 27th September 2005 03:50:52 UTC (over 11 years ago)
Hi List,

I posted this on the sourceforge support site and it was suggested that 
I move it to the list. I am still a little confused because 'phd' 
implies that the name does not have to match. I haven't tested phd's 
solution to modify the join name as described. However, does the default 
still need to be the class name? If not, then the traceback I get is an 
error.

cheers, Alex.

 >>This is probably a feature not a bug. It might be how
 >>SQLObject does some of its magic. If I do the following:
 >>
 >>class Person (SQLObject) :
 >>dbName = StringCol()
 >>dbAddresses = MultipleJoin('Address')
 >>
 >>class Address (SQLObject) :
 >>  dbStreet = StringCol()
 >>  person = ForeignKey('Person')
 >>
 >># Assume tables are created.
 >>
 >>p = Person(dbName='me')
 >>print p.dbAddresses
 >>
 >>a = Address(dbStreet='street',person=p)
 >>print p.dbAddresses
 >>print a.person
 >>
 >>This works as expected. However, if I change 'person'
 >>in the Address class to 'dbPerson' I get a traceback
 >>ending with: DatabaseError: no such column: person_id.
 >>This traceback occurs at line p = Person(dbName='me').
 >>
 >>It appears that the column name in Addresses,
 >>ForeignKey'ed to Person must match the class name. In
 >>addition, you cannot overwrite the column name using
 >>dbPerson = ForeignKey('Person', dbName='person').
 >>
 >>Am I correct that the column name must match the
 >>reference class to use ForeignKey?
 >
 >Date: 2005-09-23 22:22
 >Sender: phd
 >It should, but not must. Additionally, you can override join
 >column name:
 >dbAddresses = MultipleJoin('Address',
 >joinColumn="db_person_id")
 >I would very much like to recommend you to discuss such
 >things in the mailing list for SQLObject.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
 
CD: 3ms