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

Method test_delete_orphan_dynamic

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

Source from the content-addressed store, hash-verified

2511 eq_(sess.execute(select(func.count("*")).select_from(a)).scalar(), 1)
2512
2513 def test_delete_orphan_dynamic(self):
2514 a, A, B, b, atob = (
2515 self.tables.a,
2516 self.classes.A,
2517 self.classes.B,
2518 self.tables.b,
2519 self.tables.atob,
2520 )
2521
2522 self.mapper_registry.map_imperatively(
2523 A,
2524 a,
2525 # if no backref here, delete-orphan
2526 properties={
2527 "bs": relationship(
2528 B,
2529 secondary=atob,
2530 cascade="all, delete-orphan",
2531 single_parent=True,
2532 lazy="dynamic",
2533 )
2534 },
2535 )
2536 # failed until [ticket:427] was fixed
2537 self.mapper_registry.map_imperatively(B, b)
2538
2539 sess = fixture_session()
2540 b1 = B(data="b1")
2541 a1 = A(data="a1", bs=[b1])
2542 sess.add(a1)
2543 sess.flush()
2544
2545 a1.bs.remove(b1)
2546 sess.flush()
2547 eq_(
2548 sess.execute(select(func.count("*")).select_from(atob)).scalar(), 0
2549 )
2550 eq_(sess.execute(select(func.count("*")).select_from(b)).scalar(), 0)
2551 eq_(sess.execute(select(func.count("*")).select_from(a)).scalar(), 1)
2552
2553 def test_delete_orphan_cascades(self):
2554 a, A, c, b, C, 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
BClass · 0.70
AClass · 0.70
addMethod · 0.45
flushMethod · 0.45
removeMethod · 0.45
scalarMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected