MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_load_m2o

Method test_load_m2o

test/orm/test_selectin_relations.py:2313–2345  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2311 )
2312
2313 def test_load_m2o(self):
2314 A, B = self.classes("A", "B")
2315
2316 session = fixture_session()
2317
2318 def go():
2319 q = session.query(B).options(selectinload(B.a)).order_by(B.id)
2320 return q.all()
2321
2322 result = self.assert_sql_execution(
2323 testing.db,
2324 go,
2325 CompiledSQL(
2326 "SELECT b.id AS b_id, b.a_id1 AS b_a_id1, b.a_id2 AS b_a_id2 "
2327 "FROM b ORDER BY b.id",
2328 {},
2329 ),
2330 CompiledSQL(
2331 "SELECT a.id1, a.id2 FROM a "
2332 "WHERE (a.id1, a.id2) IN (__[POSTCOMPILE_primary_keys])",
2333 [{"primary_keys": [(i, i + 2) for i in range(1, 20)]}],
2334 ),
2335 )
2336 as_ = [A(id1=i, id2=i + 2) for i in range(1, 20)]
2337
2338 eq_(
2339 result,
2340 [
2341 B(id=(i * 6) + j, a=as_[i - 1])
2342 for i in range(1, 20)
2343 for j in range(6)
2344 ],
2345 )
2346
2347
2348class ChunkingTest(fixtures.DeclarativeMappedTest):

Callers

nothing calls this directly

Calls 6

fixture_sessionFunction · 0.90
CompiledSQLClass · 0.90
eq_Function · 0.90
assert_sql_executionMethod · 0.80
AClass · 0.70
BClass · 0.70

Tested by

no test coverage detected