i can tell you what it probably is;  currently, the "backrefs" you  
have set up also need an explicit primary join condition to be set  
up, since by default its going to create the relationship  
corresponding to the foreign keys:

food_mapper = mapper(Food, foods_table, properties=dict(
         wanted = relation(Lunch,
             primaryjoin=lunch_table.c.want_id==foods_table.c.id,
             backref=backref("want",  
primaryjoin=lunch_table.c.want_id==foods_table.c.id)),
         notwanted = relation(Lunch,
             primaryjoin=lunch_table.c.dontwant_id==foods_table.c.id,
             backref=backref("dontwant",  
primaryjoin=lunch_table.c.dontwant_id==foods_table.c.id))
     )
)

since someone else had exactly this same problem two days ago, you  
might also want to instead try rev. 1748 where I just made a change  
to propigate the explicit primary/secondary join conditions to the  
backref, if the backref was specified as just a string keyname  
without the "backref()" function being used.

On Jul 26, 2006, at 11:29 AM, Kevin Dangoor wrote:

> I'm not certain if I'm doing something wrong here, or if this is a
> bug. There's a test module at the end of this message.
>
> I've got a table that has two separate columns pointing back to
> another table. I've set up relations for both of those and I used
> primaryjoin to specify which field is used for each relation (that's
> where I might be going wrong). The first suspicious thing I see in the
> log is an INSERT into this table where both values are the same:
>
> [2006-07-26 11:23:01,523] [engine]: INSERT INTO lunch (want_id,
> dontwant_id) VALUES (?, ?)
> [2006-07-26 11:23:01,523] [engine]: [7, 7]
>
> and the next suspicious thing is a query at the end that is guaranteed
> to not produce results:
>
> [2006-07-26 11:23:01,531] [engine]: SELECT foods.id AS foods_id,
> foods.name AS foods_name
> FROM foods
> WHERE foods.id = ? AND foods.id = ? ORDER BY foods.oid
> [2006-07-26 11:23:01,531] [engine]: [2, 1]
>
>
> I think this scenario *should* work, but I could certainly be doing
> something wrong.
>
> Thanks!
>
> Kevin
>
>
>
> from sqlalchemy import *
>
> engine = create_engine("sqlite://memory", echo=True)
> metadata = BoundMetaData(engine)
> session = create_session(bind_to=engine)
>
> foods_table = Table("foods", metadata,
>     Column("id", Integer, primary_key=True),
>     Column("name", String)
> )
>
> lunch_table = Table("lunch", metadata,
>     Column("want_id", Integer, ForeignKey("foods.id")),
>     Column("id", Integer, primary_key=True),
>     Column("dontwant_id", Integer, ForeignKey("foods.id"))
> )
>
> class Food(object):
>     pass
>
> class Lunch(object):
>     pass
>
> food_mapper = mapper(Food, foods_table, properties=dict(
>         wanted = relation(Lunch,
>             primaryjoin=lunch_table.c.want_id==foods_table.c.id,
>             backref="want"),
>         notwanted = relation(Lunch,
>             primaryjoin=lunch_table.c.dontwant_id==foods_table.c.id,
>             backref="dontwant")
>     )
> )
>
> lunch_mapper = mapper(Lunch, lunch_table)
>
> def test_food():
>     metadata.create_all()
>     burger = Food()
>     burger.name="Burger"
>     session.save(burger)
>     dosa = Food()
>     dosa.name = "Masala Dosa"
>     session.save(dosa)
>     lunch = Lunch()
>     lunch.want = dosa
>     lunch.dontwant = burger
>     session.save(lunch)
>     session.flush()
>     lunch = session.get(Lunch, 1)
>     print lunch.want.name
>     assert lunch.want.name == "Masala Dosa"
>     print lunch.dontwant.name
>     assert lunch.dontwant.name == "Burger"
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys -- and earn  
> cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to