[Sqlalchemy-tickets] Issue #3233: unexpected/inconsistent aliasing applied to single-table inh subc
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2014-10-23 05:03:51
|
New issue 3233: unexpected/inconsistent aliasing applied to single-table inh subclass in query.join() https://bitbucket.org/zzzeek/sqlalchemy/issue/3233/unexpected-inconsistent-aliasing-applied Mike Bayer: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = "a" id = Column(Integer, primary_key=True) type = Column(String) __mapper_args__ = { 'polymorphic_on': type, 'polymorphic_identity': 'a' } class ASub1(A): __mapper_args__ = { 'polymorphic_identity': 'asub1' } class ASub2(A): __mapper_args__ = { 'polymorphic_identity': 'asub2' } class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) a1_id = Column(Integer, ForeignKey("a.id")) a2_id = Column(Integer, ForeignKey("a.id")) a1 = relationship("A", primaryjoin="B.a1_id == A.id", backref='b1') a2 = relationship("A", primaryjoin="B.a2_id == A.id", backref='b2') s = Session() print s.query(ASub1).join(B, ASub1.b1).join(ASub2, B.a2) print s.query(ASub1).join(B, ASub1.b1).join(ASub2, ASub2.id == B.a2_id) ``` first query: ``` #!sql SELECT a.id AS a_id, a.type AS a_type FROM a JOIN b ON b.a1_id = a.id JOIN a ON b.a2_id = a.id AND a.type IN (:type_1) WHERE a.type IN (:type_2) ``` second query, it's automatigically aliasing ASub2, bizarrely *without* the relationship: ``` #!sql SELECT a.id AS a_id, a.type AS a_type FROM a JOIN b ON b.a1_id = a.id JOIN a AS a_1 ON a_1.id = b.a2_id AND a_1.type IN (:type_1) WHERE a_1.type IN (:type_2) ``` this is really bad, is this happening with joined inheritance, whats the rules for the magic aliasing here? changing this is going to be really backwards incompatible. |