[sqlalchemy] complex many to many relationship

2013-03-27 Thread Kevin S
Setup: I have been learning SQL Alchemy to build a prototype (proof of concept) Flask app for our internal website. We want to replace our current site, which is made entirely of slow python CGIs and raw SQL. Our database (Postgres) is fairly large, but has some unusual table relationships, and

Re: [sqlalchemy] complex many to many relationship

2013-03-27 Thread Simon King
On Wed, Mar 27, 2013 at 4:13 PM, Kevin S kevinrst...@gmail.com wrote: Setup: I have been learning SQL Alchemy to build a prototype (proof of concept) Flask app for our internal website. We want to replace our current site, which is made entirely of slow python CGIs and raw SQL. Our database

Re: [sqlalchemy] complex many to many relationship

2013-03-27 Thread Kevin S
Thanks. I have it working for the Marker to Reference_Assoc relationship: Marker.referenceAssocs = relationship(ReferenceAssoc, primaryjoin=and_(ReferenceAssoc._mgitype_key==2, ReferenceAssoc._object_key==Marker._marker_key), foreign_keys=[Marker._marker_key],

Re: [sqlalchemy] complex many to many relationship

2013-03-27 Thread Kevin S
Also, is it appropriate to define a backref here? It returns wrong data. When I get a ReferenceAssoc object and get its marker, it generates a query with a clause like: reference_assoc._mgitype_key = @_mgitype_key_1 AND @param_1 = marker._marker_key and these params :

Re: [sqlalchemy] complex many to many relationship

2013-03-27 Thread Kevin S
Ok, I'm sorry to be confusing. But this backref thing, it isn't returning random results, but the join condition is all wrong. It is taking a ReferenceAssoc object with type_key = 11 and object_key=215, and making the where clause I showed. So I get back a marker with marker_key 215, but really