I have tables with compound primary keys, like this:

# table task
# Individual task for a service
task = Table('task',
    Column('system_id',
           Integer,
           primary_key=True,
           nullable=False,
    ),
    Column('id',
           Integer,
           Sequence(optional=True),
           primary_key=True,
           nullable=False,
    ),

<snip>


Now in another table I want to refer to these task records.
(an entirely made up example):

sub_task = Table('sub_task',
    Column('system_id',
           Integer,
           primary_key=True,
           nullable=False,
    ),
    Column('id',
           Integer,
           Sequence(optional=True),
           primary_key=True,
           nullable=False,
    ),

   Column('task',
       Integer,
       ForeignKey('tasks.id')
    ),

<snip>

But, when sub_task references it's parent task, it also has to include system_id in the join.

I guess I have to specify this using a custom join condition in an explicit mapper?

something along the lines of the example "boston_addresses" in the docs?

http://www.sqlalchemy.org/docs/adv_datamapping.myt#adv_datamapping_relations_customjoin

except I'd use

primaryjoin = and_(sub_task.c.task = task.c.id, sub_task.c.system_id = task.c.system_id)



Does that seem correct?

Or is there an easier way to do this in meta data, perhaps Table accepting some kind of Relationship object?



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to