MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_against_select

Method test_against_select

test/orm/test_eager_relations.py:2239–2269  ·  view source on GitHub ↗

test eager loading of a mapper which is against a select

(self)

Source from the content-addressed store, hash-verified

2237 self.assert_sql_count(testing.db, go, 1)
2238
2239 def test_against_select(self):
2240 """test eager loading of a mapper which is against a select"""
2241
2242 users, items, order_items, orders, Item, User, Order = (
2243 self.tables.users,
2244 self.tables.items,
2245 self.tables.order_items,
2246 self.tables.orders,
2247 self.classes.Item,
2248 self.classes.User,
2249 self.classes.Order,
2250 )
2251
2252 s = sa.select(orders).where(orders.c.isopen == 1).alias("openorders")
2253
2254 self.mapper_registry.map_imperatively(
2255 Order, s, properties={"user": relationship(User, lazy="joined")}
2256 )
2257 self.mapper_registry.map_imperatively(User, users)
2258 self.mapper_registry.map_imperatively(Item, items)
2259
2260 q = fixture_session().query(Order)
2261 eq_(
2262 [Order(id=3, user=User(id=7)), Order(id=4, user=User(id=9))],
2263 q.all(),
2264 )
2265
2266 q = q.select_from(s.join(order_items).join(items)).filter(
2267 ~Item.id.in_([1, 2, 5])
2268 )
2269 eq_([Order(id=3, user=User(id=7))], q.all())
2270
2271 def test_aliasing(self):
2272 """test that eager loading uses aliases to insulate the eager

Callers

nothing calls this directly

Calls 15

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
OrderClass · 0.70
UserClass · 0.70
aliasMethod · 0.45
whereMethod · 0.45
selectMethod · 0.45
queryMethod · 0.45
allMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected