MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_cascade_delete

Method test_cascade_delete

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

Source from the content-addressed store, hash-verified

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