[SQLObject] Col naming in MultipleJoin
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: deelan <de...@in...> - 2003-05-10 17:26:00
|
hi there, i'm starting to play around with sqlobject 0.3, i'm following the html pages and trying out things described in the manual. i'm having troubles to correctly name a foreign key column using multiplejoin. for example, using this two classes: class PhoneNumber(SQLObject): """Phone number""" _table = "number" _idName = "NumberId" _columns = [ Col("PersonID", dbName="PersonId", foreignKey="Person"), Col("phone", dbName="Phone"), Col("type", dbName="PhoneType") ] class Person(SQLObject): """Person in address book""" _table = "person" _idName = "PersonId" _columns = [ Col("firstName", dbName="FName"), Col("lastName", dbName="LName"), ] _joins = [MultipleJoin('PhoneNumber', joinColumn='PersonId')] in phonenumber class, "PersonID" column must named "PersonID" with correct "ID" case both in the class and in the DB, it seems to ignore dbName="" value i specify in the col constructor. to maintain consistency with my db schema it would be better to name field as PersonId (see Person class). infact if i change phonenumber "PersonID" with "PersonId" sqlobject throws out an error:"All foreign key columns must end with 'ID'" perhaps i'm missing something obvious here. linked to this issue adding a new phonenumber to person "p" instance requies the oddly named "PersonID" p = Person(1) this fails: pn = PhoneNumber.new(phone='666', type='home', PersonId=p.id) this works: pn = PhoneNumber.new(phone='666', type='home', PersonID=p.id) please note, you access person's unique id with p.id (lowercase) but you have to name Col named "PersonID" ;( any help would be appreciated. thanks. PS: BTW i've just found that this works: p = Person(1) pn = PhoneNumber.new(phone='666', type='home', Person=p) |