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

Method test_basic

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

Source from the content-addressed store, hash-verified

4617 )
4618
4619 def test_basic(self):
4620 nodes = self.tables.nodes
4621
4622 class Node(ComparableEntity):
4623 def append(self, node):
4624 self.children.append(node)
4625
4626 self.mapper_registry.map_imperatively(
4627 Node,
4628 nodes,
4629 properties={
4630 "children": relationship(
4631 Node, lazy="joined", join_depth=3, order_by=nodes.c.id
4632 )
4633 },
4634 )
4635 sess = fixture_session()
4636 n1 = Node(data="n1")
4637 n1.append(Node(data="n11"))
4638 n1.append(Node(data="n12"))
4639 n1.append(Node(data="n13"))
4640 n1.children[1].append(Node(data="n121"))
4641 n1.children[1].append(Node(data="n122"))
4642 n1.children[1].append(Node(data="n123"))
4643 sess.add(n1)
4644 sess.flush()
4645 sess.expunge_all()
4646
4647 def go():
4648 d = sess.query(Node).filter_by(data="n1").all()[0]
4649 eq_(
4650 Node(
4651 data="n1",
4652 children=[
4653 Node(data="n11"),
4654 Node(
4655 data="n12",
4656 children=[
4657 Node(data="n121"),
4658 Node(data="n122"),
4659 Node(data="n123"),
4660 ],
4661 ),
4662 Node(data="n13"),
4663 ],
4664 ),
4665 d,
4666 )
4667
4668 self.assert_sql_count(testing.db, go, 1)
4669
4670 sess.expunge_all()
4671
4672 def go():
4673 d = sess.query(Node).filter_by(data="n1").first()
4674 eq_(
4675 Node(
4676 data="n1",

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