def test_double(self):

        users, orders, User, Address, Order, addresses = (
            self.tables.users,
            self.tables.orders,
            self.classes.User,
            self.classes.Address,
            self.classes.Order,
            self.tables.addresses)

        openorders = sa.alias(orders, 'openorders')
        closedorders = sa.alias(orders, 'closedorders')

        mapper(Address, addresses)
        mapper(Order, orders)

        open_mapper = mapper(Order, openorders, non_primary=True)
        closed_mapper = mapper(Order, closedorders, non_primary=True)

        mapper(User, users, properties=dict(
            addresses=relationship(
                Address, lazy='joined', order_by=addresses.c.id),
            open_orders=relationship(
                open_mapper,
                primaryjoin=sa.and_(openorders.c.isopen == 1,
                                    users.c.id == openorders.c.user_id),
                lazy='joined', order_by=openorders.c.id),
            closed_orders=relationship(
                closed_mapper,
                primaryjoin=sa.and_(closedorders.c.isopen == 0,
                                    users.c.id == closedorders.c.user_id),
                lazy='joined', order_by=closedorders.c.id)))

        q = create_session().query(User).order_by(User.id)

        def go():
            eq_([
                User(
                    id=7,
                    addresses=[Address(id=1)],
                    open_orders=[Order(id=3)],
                    closed_orders=[Order(id=1), Order(id=5)]
                ),
                User(
                    id=8,
                    addresses=[Address(id=2), Address(id=3), Address(id=4)],
                    open_orders=[],
                    closed_orders=[]
                ),
                User(
                    id=9,
                    addresses=[Address(id=5)],
                    open_orders=[Order(id=4)],
                    closed_orders=[Order(id=2)]
                ),
                User(id=10)

                ], q.all())
        self.assert_sql_count(testing.db, go, 1)
Eager loading with two relationships simultaneously,
dataset/ETHPy150Open zzzeek/sqlalchemy/test/orm/test_eager_relations.py/EagerTest.test_double