MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_basic

Method test_basic

test/orm/test_subquery_relations.py:2440–2514  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2438 )
2439
2440 def test_basic(self):
2441 nodes = self.tables.nodes
2442
2443 class Node(ComparableEntity):
2444 def append(self, node):
2445 self.children.append(node)
2446
2447 self.mapper_registry.map_imperatively(
2448 Node,
2449 nodes,
2450 properties={
2451 "children": relationship(
2452 Node, lazy="subquery", join_depth=3, order_by=nodes.c.id
2453 )
2454 },
2455 )
2456 sess = fixture_session()
2457 n1 = Node(data="n1")
2458 n1.append(Node(data="n11"))
2459 n1.append(Node(data="n12"))
2460 n1.append(Node(data="n13"))
2461 n1.children[1].append(Node(data="n121"))
2462 n1.children[1].append(Node(data="n122"))
2463 n1.children[1].append(Node(data="n123"))
2464 n2 = Node(data="n2")
2465 n2.append(Node(data="n21"))
2466 n2.children[0].append(Node(data="n211"))
2467 n2.children[0].append(Node(data="n212"))
2468
2469 sess.add(n1)
2470 sess.add(n2)
2471 sess.flush()
2472 sess.expunge_all()
2473
2474 def go():
2475 d = (
2476 sess.query(Node)
2477 .filter(Node.data.in_(["n1", "n2"]))
2478 .order_by(Node.data)
2479 .all()
2480 )
2481 eq_(
2482 [
2483 Node(
2484 data="n1",
2485 children=[
2486 Node(data="n11"),
2487 Node(
2488 data="n12",
2489 children=[
2490 Node(data="n121"),
2491 Node(data="n122"),
2492 Node(data="n123"),
2493 ],
2494 ),
2495 Node(data="n13"),
2496 ],
2497 ),

Callers

nothing calls this directly

Calls 9

appendMethod · 0.95
relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
assert_sql_countMethod · 0.80
NodeClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45

Tested by

no test coverage detected