[Sqlalchemy-tickets] Issue #3505: join targeting broken for joined-inh-> joined-inh w/ secondary (z
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-08-03 16:59:52
|
New issue 3505: join targeting broken for joined-inh-> joined-inh w/ secondary https://bitbucket.org/zzzeek/sqlalchemy/issues/3505/join-targeting-broken-for-joined-inh Mike Bayer: unfortunately the patch in #3366 does not resolve ``` #!python from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session, relationship from sqlalchemy import Column, String, Integer from sqlalchemy.schema import ForeignKey Base = declarative_base() class Object(Base): """ Object ORM """ __tablename__ = 'object' type = Column(String(30)) __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphic_on': type } id = Column(Integer, primary_key=True) name = Column(String(256)) class A(Object): __tablename__ = 'a' __mapper_args__ = { 'polymorphic_identity': 'a', } id = Column(Integer, ForeignKey('object.id'), primary_key=True) b_list = relationship( 'B', secondary='a_b_association', backref='a_list' ) class B(Object): __tablename__ = 'b' __mapper_args__ = { 'polymorphic_identity': 'b', } id = Column(Integer, ForeignKey('object.id'), primary_key=True) class ABAssociation(Base): __tablename__ = 'a_b_association' a_id = Column(Integer, ForeignKey('a.id'), primary_key=True) b_id = Column(Integer, ForeignKey('b.id'), primary_key=True) class X(Base): __tablename__ = 'x' id = Column(Integer, primary_key=True) name = Column(String(30)) obj_id = Column(Integer, ForeignKey('object.id')) obj = relationship('Object', backref='x_list') s = Session() # works q = s.query(B).\ join(B.a_list, 'x_list').filter(X.name == 'x1') print q # fails q = s.query(B).\ join(B.a_list, A.x_list).filter(X.name == 'x1') print q ``` |