first off, note that this style of relationship is severely limited with regards to the arrangements of A->B->C. the C's attached to B's are intertwined with the B's that are attached to A's and it will be very confusing to manage those relationships independently of each other. if you are looking for select efficiency, you would probably be better off just doing normal joins from A->B->C including association tables if they are many-to-many relationships; SA can eager load such a relationship in one query.
anyway, the closest SA can get to this is to represent your "R" table as a relationship object with its own mapper: class ABCRelation(object):pass mapper(A, Atable) mapper(B,Btable) mapper(C,Ctable) mapper(ABCRelation, Rtable, primary_key=[R.c.a_id, R.c.b_id, R.c.c_id], properties={ 'as':relation(A, backref='relations'), 'bs':relation(B, backref='relations'), 'cs':relation(C, backref='relations') }, allow_null_pks=True) a = A() b = B() c = C() r = ABCRelation() r.a = a r.b = b r.c = c [session.save(x) for x in [a,b,c,r]] session.flush() etc the good news is that the latest trunk of SQLAlchemy (i.e. release 0.2.9) will even keep it straight if you delete an ABCRelation and create a new one with the same relationships in one session; it will turn the DELETE/INSERT into an UPDATE. On Sep 27, 2006, at 1:10 PM, Martin Kaffanke wrote: > Hi there! > > I don't know if my english is good enaugh to tell you what I want. > > I have 3 Tables, lets tell them A, B and C. The relations: > > An A kann have some B's and a B can have some C's. But the main > Select > will be: > > and_(A.c.a_id==B.c.a_id, B.c.b_id==C.c.b_id, C.c.c_id=some_integer) > > So now there are two joins. > As you see, we have two joins. We would have only one by doing > > A B C and a R table, where R has all three ID's: > > R.c.a_id > R.c.b_id > R.c.c_id > > A relation table... > > and_(A.c.a_id==R.c.a_id, C.c.c_id==some_integer) > > would be enaught. > > But how can I save data this way with a mapper? > > Martin > > > ---------------------------------------------------------------------- > --- > 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