MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_no_depth

Method test_no_depth

test/orm/test_subquery_relations.py:2678–2736  ·  view source on GitHub ↗

no join depth is set, so no eager loading occurs.

(self)

Source from the content-addressed store, hash-verified

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."""
2680
2681 nodes = self.tables.nodes
2682
2683 class Node(ComparableEntity):
2684 def append(self, node):
2685 self.children.append(node)
2686
2687 self.mapper_registry.map_imperatively(
2688 Node,
2689 nodes,
2690 properties={"children": relationship(Node, lazy="subquery")},
2691 )
2692 sess = fixture_session()
2693 n1 = Node(data="n1")
2694 n1.append(Node(data="n11"))
2695 n1.append(Node(data="n12"))
2696 n1.append(Node(data="n13"))
2697 n1.children[1].append(Node(data="n121"))
2698 n1.children[1].append(Node(data="n122"))
2699 n1.children[1].append(Node(data="n123"))
2700 n2 = Node(data="n2")
2701 n2.append(Node(data="n21"))
2702 sess.add(n1)
2703 sess.add(n2)
2704 sess.flush()
2705 sess.expunge_all()
2706
2707 def go():
2708 d = (
2709 sess.query(Node)
2710 .filter(Node.data.in_(["n1", "n2"]))
2711 .order_by(Node.data)
2712 .all()
2713 )
2714 eq_(
2715 [
2716 Node(
2717 data="n1",
2718 children=[
2719 Node(data="n11"),
2720 Node(
2721 data="n12",
2722 children=[
2723 Node(data="n121"),
2724 Node(data="n122"),
2725 Node(data="n123"),
2726 ],
2727 ),
2728 Node(data="n13"),
2729 ],
2730 ),
2731 Node(data="n2", children=[Node(data="n21")]),
2732 ],
2733 d,
2734 )
2735

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