user2529837
user2529837

Reputation: 51

Sqlalchemy. How to set the defaul polymorphic innerjoin?

How to set the defaul polymorphic innerjoin?

class Some(Base):
    __tablename__ = 'some'
    @declared_attr
    def __mapper_args__(cls):
        return  {'polymorphic_identity': '%s' % cls.__tablename__,
                 'polymorphic_on': cls._type,
                 'with_polymorphic': '*',
                 'polymorphic_innerjoin': True # how to do it?
        }

Upvotes: 0

Views: 57

Answers (1)

zzzeek
zzzeek

Reputation: 75117

an INNER join is used if you actually query for that type specifically, no with_polymorphic needed:

sess.query(MySubClass).all()

If you are querying for Some objects (i.e. your base), that means you want objects that are also not of type MySubClass, so an OUTER join is necessary there.

Upvotes: 1

Related Questions