abstractconcretebase polish

Issue #2950 resolved
Mike Bayer repo owner created an issue

seems to not be putting the class name into declarative registry:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base, AbstractConcreteBase

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)

class BC(AbstractConcreteBase, Base):
    pass

class B(BC):
    __tablename__ = 'b'
    id = Column(Integer, primary_key=True)

    a_id = Column(Integer, ForeignKey('a.id'))
    __mapper_args__ = {
        "polymorphic_identity": "b",
        "concrete": True
    }

class C(BC):
    __tablename__ = 'c'
    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('a.id'))
    __mapper_args__ = {
        "polymorphic_identity": "c",
        "concrete": True
    }

# fails
#A.collection = relationship("BC", primaryjoin="BC.a_id == A.id")

# workaround
configure_mappers()
A.collection = relationship(BC, primaryjoin=BC.a_id == A.id)

check if there's a dupe for this also

Comments (1)

  1. Log in to comment