MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_options

Method test_options

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

Source from the content-addressed store, hash-verified

2621 self.assert_sql_count(testing.db, go, 3)
2622
2623 def test_options(self):
2624 nodes = self.tables.nodes
2625
2626 class Node(ComparableEntity):
2627 def append(self, node):
2628 self.children.append(node)
2629
2630 self.mapper_registry.map_imperatively(
2631 Node,
2632 nodes,
2633 properties={"children": relationship(Node, order_by=nodes.c.id)},
2634 )
2635 sess = fixture_session()
2636 n1 = Node(data="n1")
2637 n1.append(Node(data="n11"))
2638 n1.append(Node(data="n12"))
2639 n1.append(Node(data="n13"))
2640 n1.children[1].append(Node(data="n121"))
2641 n1.children[1].append(Node(data="n122"))
2642 n1.children[1].append(Node(data="n123"))
2643 sess.add(n1)
2644 sess.flush()
2645 sess.expunge_all()
2646
2647 def go():
2648 d = (
2649 sess.query(Node)
2650 .filter_by(data="n1")
2651 .order_by(Node.id)
2652 .options(
2653 subqueryload(Node.children).subqueryload(Node.children)
2654 )
2655 .first()
2656 )
2657 eq_(
2658 Node(
2659 data="n1",
2660 children=[
2661 Node(data="n11"),
2662 Node(
2663 data="n12",
2664 children=[
2665 Node(data="n121"),
2666 Node(data="n122"),
2667 Node(data="n123"),
2668 ],
2669 ),
2670 Node(data="n13"),
2671 ],
2672 ),
2673 d,
2674 )
2675
2676 self.assert_sql_count(testing.db, go, 3)
2677
2678 def test_no_depth(self):
2679 """no join depth is set, so no eager loading occurs."""

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