customer_organization = Table('base_user_customer_organization', ModelBase.
    metadata, Column('user_id', Integer, ForeignKey('base_user.id')),
    Column('org_id', Integer, ForeignKey('base_user.id')))


class BaseUser(ModelBase):
    __tablename__ = 'base_user'
id = Column(Integer, primary_key=True, nullable=False)
org = Column(Boolean, default=False, nullable=False)
__mapper_args__ = {'polymorphic_on': org}
customers = relationship('BaseUser', backref=backref('organization',
    order_by=id), secondary=customer_organization, primaryjoin=id ==
    customer_organization.c.org_id and org == True, secondaryjoin=id ==
    customer_organization.c.user_id and org == False)


class CustomerUser(BaseUser):
    __mapper_args__ = {'polymorphic_identity': False}


class OrganizationUser(BaseUser):
    __mapper_args__ = {'polymorphic_identity': True}
SQLALchemy Many to Many model relationship configuration with polymorphic models