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

Method test_options

test/orm/test_eager_relations.py:4803–4876  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4801 self.assert_sql_count(testing.db, go, 1)
4802
4803 def test_options(self):
4804 nodes = self.tables.nodes
4805
4806 class Node(ComparableEntity):
4807 def append(self, node):
4808 self.children.append(node)
4809
4810 self.mapper_registry.map_imperatively(
4811 Node,
4812 nodes,
4813 properties={
4814 "children": relationship(
4815 Node, lazy="select", order_by=nodes.c.id
4816 )
4817 },
4818 )
4819 sess = fixture_session()
4820 n1 = Node(data="n1")
4821 n1.append(Node(data="n11"))
4822 n1.append(Node(data="n12"))
4823 n1.append(Node(data="n13"))
4824 n1.children[1].append(Node(data="n121"))
4825 n1.children[1].append(Node(data="n122"))
4826 n1.children[1].append(Node(data="n123"))
4827 sess.add(n1)
4828 sess.flush()
4829 sess.expunge_all()
4830
4831 def go():
4832 d = (
4833 sess.query(Node)
4834 .filter_by(data="n1")
4835 .order_by(Node.id)
4836 .options(joinedload(Node.children, Node.children))
4837 .first()
4838 )
4839 eq_(
4840 Node(
4841 data="n1",
4842 children=[
4843 Node(data="n11"),
4844 Node(
4845 data="n12",
4846 children=[
4847 Node(data="n121"),
4848 Node(data="n122"),
4849 Node(data="n123"),
4850 ],
4851 ),
4852 Node(data="n13"),
4853 ],
4854 ),
4855 d,
4856 )
4857
4858 self.assert_sql_count(testing.db, go, 2)
4859
4860 def go():

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected