Hello, I have been struggling for a few hours with the following issue. First, the models:
stack_resources = db.Table('stack_resources', db.Column('stack_id', db.Integer, db.ForeignKey('stack.id')), db.Column('resource_id', db.Integer, db.ForeignKey('resource.id')) ) class Stack(BaseObject, db.Model): id = some primary key resources = db.relation('Resource', secondary=stack_resources, secondaryjoin="and_(Resource.id==stack_resources.c.resource_id, \ Resource.top_parent_resource==True)", backref=db.backref('stacks')) class Resource(BaseObject, db.Model): id = some primary key top_parent_resource = db.Column(db.Boolean) The issue lies with the query emitted. Here's the query for getting the Resources associated with a stack: SELECT ALL THE THINGS FROM RESOURCES FROM resource, stack_resources WHERE %s = stack_resources.stack_id AND resource.id = stack_resources.resource_id AND resource.top_parent_resource = %s Basically, what appears to be missing is "AND stack.id = stack_resources.stack_id". Anything I'm missing in the relationship configuration that would make that happen? Thank you, Kuba -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/U2lMskkaSaYJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.