Menu

#3 ForeignKey Column Name Limitation

closed
nobody
None
5
2005-09-23
2005-09-22
aledain
No

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?

cheers, Alex.

Discussion

  • Oleg Broytman

    Oleg Broytman - 2005-09-23
    • status: open --> closed
     
  • Oleg Broytman

    Oleg Broytman - 2005-09-23

    Logged In: YES
    user_id=4799

    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.

     

Log in to post a comment.