MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_delete_orphan_cascades

Method test_delete_orphan_cascades

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

Source from the content-addressed store, hash-verified

2550 eq_(sess.execute(select(func.count("*")).select_from(a)).scalar(), 1)
2551
2552 def test_delete_orphan_cascades(self):
2553 a, A, c, b, C, B, atob = (
2554 self.tables.a,
2555 self.classes.A,
2556 self.tables.c,
2557 self.tables.b,
2558 self.classes.C,
2559 self.classes.B,
2560 self.tables.atob,
2561 )
2562
2563 self.mapper_registry.map_imperatively(
2564 A,
2565 a,
2566 properties={
2567 # if no backref here, delete-orphan failed until #
2568 # [ticket:427] was fixed
2569 "bs": relationship(
2570 B,
2571 secondary=atob,
2572 cascade="all, delete-orphan",
2573 single_parent=True,
2574 )
2575 },
2576 )
2577 self.mapper_registry.map_imperatively(
2578 B,
2579 b,
2580 properties={"cs": relationship(C, cascade="all, delete-orphan")},
2581 )
2582 self.mapper_registry.map_imperatively(C, c)
2583
2584 sess = fixture_session()
2585 b1 = B(data="b1", cs=[C(data="c1")])
2586 a1 = A(data="a1", bs=[b1])
2587 sess.add(a1)
2588 sess.flush()
2589
2590 a1.bs.remove(b1)
2591 sess.flush()
2592 eq_(
2593 sess.execute(select(func.count("*")).select_from(atob)).scalar(), 0
2594 )
2595 eq_(sess.execute(select(func.count("*")).select_from(b)).scalar(), 0)
2596 eq_(sess.execute(select(func.count("*")).select_from(a)).scalar(), 1)
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 = (

Callers

nothing calls this directly

Calls 15

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
selectFunction · 0.90
map_imperativelyMethod · 0.80
BClass · 0.70
CClass · 0.70
AClass · 0.70
addMethod · 0.45
flushMethod · 0.45
removeMethod · 0.45
scalarMethod · 0.45

Tested by

no test coverage detected