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')
})
did the trick.
Thanks!
On Aug 23, 8:58 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> 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 declarative_base
> > from sqlalchemy import Table, Column, Integer, String, MetaData,
> > ForeignKey
> > from sqlalchemy.orm import relation, backref, mapper
>
> > Base = declarative_base()
> > metadata = Base.metadata
>
> > contact_table = Table('contact', metadata,
> > Column('id', Integer, primary_key=True),
> > Column('first_name', String(20)),
> > Column('last_name', String(30)))
>
> > call_table = Table('call', metadata,
> > Column('id', Integer, primary_key=True),
> > Column('subject', String(255)),
> > Column('callee_id', Integer, ForeignKey('contact.id')),
> > Column('caller_id', Integer, ForeignKey('contact.id')))
>
> > class Contact(object):
> > def __init__(self, first_name, last_name):
> > self.first_name = first_name
> > self.last_name = last_name
>
> > def __repr__(self):
> > return self.first_name + ' ' + self.last_name
>
> > mapper(Contact, contact_table)
>
> > class Call(object):
> > def __init__(self, subject, callee, caller):
> > self.subject = subject
> > self.callee = callee
> > self.caller = caller
>
> > def __repr__(self):
> > return self.subject
>
> > mapper(Call, call_table, properties={
> > 'callee':relation(Call,
> > primaryjoin=call_table.c.callee_id==contact_table.c.id,
> > backref='callee_calls'),
> > 'caller':relation(Call,
> > primaryjoin=call_table.c.caller_id==contact_table.c.id,
> > backref='caller_calls')
> > })
>
> > c = Contact('my_first_name', 'my_last_name')
>
> > I get a long error:
> > sqlalchemy.exc.ArgumentError: Could not locate any equated, locally
> > mapped column pairs for primaryjoin condition 'call.caller_id =
> > contact.id' on relation Call.caller. For more relaxed rules on join
> > conditions, the relation may be marked as viewonly=True.
>
> "callee" and "caller" relate Call to another Call. The join condition
> given does not connect "call_table" to itself and instead connects to
> "contact_table" which is not involved in the relation(). Based on the
> table it seems like "callee" and "caller" should relate to a Contact,
> not a Call.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---