youre constructing your relations incorrectly; it should look like:

map_user = mapper(User, tm_user,
    properties = {
'outbox' : relation (Item,primaryjoin=tm_user.c.userid==Item.c.from_uid),
        'inbox' : relation(Item,primaryjoin=tm_user.c.userid==Item.c.to_uid),
    }
    )

this will use the "primary" mapper for the Item class inside the relations; "primaryjoin" is an argument to the relation() function, not the mapper() function.

On Apr 19, 2006, at 6:54 AM, Andrew Bulhak wrote:

Hello;

I have recently started on a project using SQLAlchemy, and have run into a problem when trying to join a row in one table to two separate rows in
another.

I am working on an application in which users can send messages to each
other. I have two tables, a User table, and a Item table. They look as
follows:

tm_user = Table("user", engine,
    Column('userid', String(5), primary_key=True,
    ...
)

tm_item = Table("item", engine,
    Column("itemid", String(5), primary_key=True),
    ...
   Column('from_uid', String(5), ForeignKey("user.userid")),
   Column('to_uid', String(5), ForeignKey("user.userid"))
)

Each Item is associated with two Users: the sender ('from_uid') and the
recipient ('to_uid').   I have set up mappers like this:

map_item = mapper(Item, tm_item)
map_user = mapper(User, tm_user,
    properties = {
        'outbox' :
relation(mapper(Item,primaryjoin=tm_user.c.userid==Item.c.from_uid)),
        'inbox' : relation(mapper(Item,
primaryjoin=tm_user.c.userid==Item.c.to_uid)),
    }
    )


The problem with this is that, when I create a User object with a query
and inspect its inbox and outbox properties, I find that each one
contains only Items where both from_uid and to_uid are equal to userid.

How can I change this so that outbox only matches by from_uid and inbox
by to_uid?

Thanks,

Andrew Bulhak


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel? cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to