MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_cascade_delete

Method test_cascade_delete

test/orm/test_cascade.py:2600–2634  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2598 eq_(sess.execute(select(func.count("*")).select_from(c)).scalar(), 0)
2599
2600 def test_cascade_delete(self):
2601 a, A, B, b, atob = (
2602 self.tables.a,
2603 self.classes.A,
2604 self.classes.B,
2605 self.tables.b,
2606 self.tables.atob,
2607 )
2608
2609 self.mapper_registry.map_imperatively(
2610 A,
2611 a,
2612 properties={
2613 "bs": relationship(
2614 B,
2615 secondary=atob,
2616 cascade="all, delete-orphan",
2617 single_parent=True,
2618 )
2619 },
2620 )
2621 self.mapper_registry.map_imperatively(B, b)
2622
2623 sess = fixture_session()
2624 a1 = A(data="a1", bs=[B(data="b1")])
2625 sess.add(a1)
2626 sess.flush()
2627
2628 sess.delete(a1)
2629 sess.flush()
2630 eq_(
2631 sess.execute(select(func.count("*")).select_from(atob)).scalar(), 0
2632 )
2633 eq_(sess.execute(select(func.count("*")).select_from(b)).scalar(), 0)
2634 eq_(sess.execute(select(func.count("*")).select_from(a)).scalar(), 0)
2635
2636 def test_single_parent_error(self):
2637 a, A, B, b, atob = (

Callers

nothing calls this directly

Calls 14

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
selectFunction · 0.90
map_imperativelyMethod · 0.80
AClass · 0.70
BClass · 0.70
addMethod · 0.45
flushMethod · 0.45
deleteMethod · 0.45
scalarMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected