[SQLObject] Incorrect join column name
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Matt G. <ma...@po...> - 2003-05-11 22:54:20
|
Hi, I've only recently started experimenting with SQLObject so please forgive me if this turns out to be complete nonsense ;-). There seems to be a problem with the name that is generated for a join column when a class explicitly sets the name of the table (using _table). Here's an example: class Order(SQLObject.SQLObject): _table = 'ordr' _columns = [ SQLObject.IntCol('number', dbName='nmbr'), SQLObject.IntCol('customerID', foreignKey='Customer'), ] _joins = [SQLObject.MultipleJoin('OrderItem'),] class OrderItem(SQLObject.SQLObject): _columns = [ SQLObject.IntCol('orderID', foreignKey='Order'), SQLObject.IntCol('productID', foreignKey='Product'), SQLObject.IntCol('quantity'), ] (Ignore the Customer and Product classes - they're not relevant.) >From the above, SQLObject creates the following tables: CREATE TABLE ordr ( id serial NOT NULL, nmbr integer, customer_id integer ); CREATE TABLE order_item ( id serial NOT NULL, order_id integer, product_id integer, quantity integer ); So far, so good. However when I have an existing Order (with id=1) and I "call" order.orderItems the following SQL is executed: SELECT id FROM order_item WHERE ordr_id = 1 As you can see, ordr_id is wrong - it should be order_id. I started trying to fix the error but realised that I don't actually know what to fix - the table creation code or the join code. i.e. should the created table's column be called ordr_id or should the join SQL use order_id? If someone who understands what SQLObject's *should* be doing can tell me what to fix I will try to send a patch. - Matt |