- Fixed a recursive pickling issue in serializer, triggered
by an EXISTS or other embedded FROM construct.
+ - Declarative locates the "inherits" class using a search
+ through __bases__, to skip over mixins that are local
+ to subclasses.
+
- Declarative figures out joined-table inheritance primary join
condition even if "inherits" mapper argument is given
- explicitly. Allows mixins to be used with joined table
- inheritance.
+ explicitly.
- Declarative will properly interpret the "foreign_keys" argument
on a backref() if it's a string.
from sqlalchemy.orm import synonym as _orm_synonym, mapper, comparable_property, class_mapper
from sqlalchemy.orm.interfaces import MapperProperty
from sqlalchemy.orm.properties import PropertyLoader, ColumnProperty
+from sqlalchemy.orm.util import _is_mapped_class
from sqlalchemy import util, exceptions
from sqlalchemy.sql import util as sql_util
mapper_args = getattr(cls, '__mapper_args__', {})
if 'inherits' not in mapper_args:
- inherits = cls.__mro__[1]
- inherits = cls._decl_class_registry.get(inherits.__name__, None)
- if inherits:
- mapper_args['inherits'] = inherits
+ for c in cls.__bases__:
+ if _is_mapped_class(c):
+ mapper_args['inherits'] = cls._decl_class_registry.get(c.__name__, None)
+ break
if hasattr(cls, '__mapper_cls__'):
mapper_cls = util.unbound_method_to_callable(cls.__mapper_cls__)
# compile succeeds because inherit_condition is honored
compile_mappers()
-
+
def test_joined(self):
class Company(Base, ComparableEntity):
__tablename__ = 'companies'
def go():
assert sess.query(Person).filter(Manager.name=='dogbert').one().id
self.assert_sql_count(testing.db, go, 1)
+
+ def test_subclass_mixin(self):
+ class Person(Base, ComparableEntity):
+ __tablename__ = 'people'
+ id = Column('id', Integer, primary_key=True)
+ name = Column('name', String(50))
+ discriminator = Column('type', String(50))
+ __mapper_args__ = {'polymorphic_on':discriminator}
+
+ class MyMixin(object):
+ pass
+
+ class Engineer(MyMixin, Person):
+ __tablename__ = 'engineers'
+ __mapper_args__ = {'polymorphic_identity':'engineer'}
+ id = Column('id', Integer, ForeignKey('people.id'), primary_key=True)
+ primary_language = Column('primary_language', String(50))
+
+ assert class_mapper(Engineer).inherits is class_mapper(Person)
def test_with_undefined_foreignkey(self):
class Parent(Base):