[SQLObject] Joins: joinColumn odd behaviour
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Alan F. <ala...@gm...> - 2005-11-19 15:21:09
|
Hello, I've just figured out there're couple of errors ( i think ) in SQLObject documentation regarding joins, especially about the joinColumn usage, that should be corrected. I'm using SQLObject branch 0.7-bugfix from SVN, dated 03 November 2005. That's what I read from the main site: (MultipleJoin-OneToMany rel): joinColumn: The column name of the key that points to this table. So, if you have a table Product, and another table has a column ProductNo that points to this table, then you'd use joinColumn="ProductNo". So, this is what I think it should look ( "ProductNo" clearly refers to a sqlobject-style column, which would translate to product_no in the database schema; it doesn't look like a database column): #begin MultipleJoinTest.py class Person(SQLObject): name=StringCol(unique=True,notNone=True,alternateID=True) addresses=MultipleJoin('Addresses',joinColumn='addrPerson') class Addresses(SQLObject): address=StringCol() addrPerson=ForeignKey('Person') Person.createTable() Addresses.createTable() Person(name='Jack') Person(name='John') Person(name='Jill') Addresses(address='1st Avenue',addrPerson=Person.byName('Jack').id) Addresses(address='2nd Avenue',addrPerson=Person.byName('Jack').id) Addresses(address='3rd Avenue',addrPerson=Person.byName('John').id) Addresses(address='1st Street',addrPerson=Person.byName('John').id) Addresses(address='2nd Street',addrPerson=Person.byName('Jill').id) Addresses(address='3rd Street',addrPerson=Person.byName('Jill').id) jack=Person.byName('Jack') print jack.addresses #end MultipleJoinTest.py executing this will result in an error: ## psycopg.ProgrammingError: ERROR: column "addrperson" does not exist SELECT id FROM addresses WHERE addrPerson = 1 ## the addrPerson column doesn't get translated into 'database style' column type, which would be addr_person, and it doesn't get the additional ID field either. The only way to have it work is to change the joinColumn parameter into addr_person_id, the same column name as the database one. I have not tested this behaviour with RelatedJoin & ManyToMany because I need to set up a relation table manually, but I will very soon and report again. -- Alan Franzoni <ala...@gm...> - Togli .xyz dalla mia email per contattarmi. To contact me, remove .xyz from my email address. - GPG Key Fingerprint: 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E |