[sqlalchemy] Re: multiple foreign keys to the same table

2008-08-23 Thread Michael Bayer
On Aug 23, 2008, at 1:56 PM, Rob wrote: Hi, I'm using sqlalchemy 0.5 beta 3 and I am trying to have a Call object that contains two relations to a Contact object. One is the callee and the other is the caller. The code is as follows: from sqlalchemy.ext.declarative import

[sqlalchemy] Re: multiple foreign keys to the same table

2008-08-23 Thread Rob
Hi, You're right: mapper(Call, call_table, properties={ 'callee':relation(Contact, primaryjoin=call_table.c.callee_id==contact_table.c.id, backref='callee_calls'), 'caller':relation(Contact, primaryjoin=call_table.c.caller_id==contact_table.c.id, backref='caller_calls')

[sqlalchemy] Re: Multiple foreign keys to the same table from another table

2007-07-20 Thread Sean Davis
On Jul 20, 11:57 pm, Sean Davis [EMAIL PROTECTED] wrote: I have a table that has two columns that reference the same table in a foreign-key relationship. What do I need to specify and where to avoid the error below? class 'sqlalchemy.exceptions.ArgumentError': Error determining primary

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-21 Thread Ali
Excellent, that (expire, refresh) works. Thank-you very much. Is there a reason why it sometimes works? On Feb 20, 11:47 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Feb 20, 2007, at 12:01 PM, Ali wrote: u = User(name='Ali') u.flush() r = Receipt(user_id=u.id) r.flush() r.user is

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-21 Thread Michael Bayer
the cancelled_user may not have been lazy loaded before you flush() ed. On Feb 21, 2007, at 6:09 AM, Ali wrote: Excellent, that (expire, refresh) works. Thank-you very much. Is there a reason why it sometimes works? On Feb 20, 11:47 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Feb 20,

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Michael Bayer
On Feb 20, 12:01 pm, Ali [EMAIL PROTECTED] wrote: Here is my code (with other fields removed): stockreceipt_table = Table('stockreceipt', meta, Column('user_id', Integer, ForeignKey('user.id')), # Cancellation Column('cancelled_user_id', Integer, ForeignKey('user.id')), )

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Ali
I left out the fields for brevity of example. They both have an id column defined as primary keys. On 20 Feb, 17:11, Michael Bayer [EMAIL PROTECTED] wrote: On Feb 20, 12:01 pm, Ali [EMAIL PROTECTED] wrote: Here is my code (with other fields removed): stockreceipt_table =

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Ali
By both, I mean user and receipt tables On 20 Feb, 17:12, Ali [EMAIL PROTECTED] wrote: I left out the fields for brevity of example. They both have an id column defined as primary keys. On 20 Feb, 17:11, Michael Bayer [EMAIL PROTECTED] wrote: On Feb 20, 12:01 pm, Ali [EMAIL PROTECTED]

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Ali
Ok, from sqlalchemy import * from sqlalchemy.ext.assignmapper import assign_mapper from sqlalchemy.ext.sessioncontext import SessionContext meta = DynamicMetaData() ctx = SessionContext(create_session) def make_engine(uri=None): if uri is None: uri = 'sqlite:///:memory:'

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Michael Bayer
well I cant run the program since its not complete (no Drug, Supplier class/tables defined, etc), but if id hazard a guess id say you shouldnt be calling flush() on your class instances, since it will not flush any changes on any dependencies. call ctx.current.flush() instead. On Feb

[sqlalchemy] Re: Multiple Foreign Keys to the same table, problems with second object.

2007-02-20 Thread Ali
Thanks for the advice, and sorry I didn't provide the correct information, but ctx.current.flush() makes no difference. r.cancelled_user is (nearly: 19/20) always None immediately after the assign and flush with no database access being made. Interestingly, the user_id/user relationship is always