setattr(cls, '__mapper_args__', {'polymorphic_identity': dct['_identity'],
    'inherit_condition': (xid == Entity.id,), 'primary_key': (xid,)})
Creating self-referential tables with polymorphism in SQLALchemy