[Sqlalchemy-tickets] Issue #4350: synonym + single inheritance + mixins (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-10-19 20:45:01
|
New issue 4350: synonym + single inheritance + mixins https://bitbucket.org/zzzeek/sqlalchemy/issues/4350/synonym-single-inheritance-mixins Michael Bayer: this shouldn't seem to need @cascading though it at least works when we do that, but synonyms are inheritable. if the superclass has the synonym it should be getting mapped or at least warning there's a problem: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) type = Column(String) __mapper_options__ = { 'polymorphic_on': type } data = Column(String) class Mixin: @declared_attr def data_syn(cls): return synonym("data") @declared_attr.cascading def data_syn_cascading(cls): return synonym("data") class B(Mixin, A): __mapper_options__ = { 'polymorphic_identity': "B" } class C(B): __mapper_options__ = { 'polymorphic_identity': "C" } s = Session() # yes print(s.query(B.data).filter(B.data == 'foo')) # yes print(s.query(B.data_syn_cascading).filter(B.data_syn_cascading == 'foo')) # yes print(s.query(B.data_syn).filter(B.data_syn == 'foo')) # yes print(s.query(C.data).filter(C.data == 'foo')) # yes print(s.query(C.data_syn_cascading).filter(C.data_syn_cascading == 'foo')) # no, there's an unmapped C.data_syn property sitting there blocking it print(s.query(C.data_syn).filter(C.data_syn == 'foo')) ``` |