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

Method test_delete_orphan

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

Source from the content-addressed store, hash-verified

2471 pass
2472
2473 def test_delete_orphan(self):
2474 a, A, B, b, atob = (
2475 self.tables.a,
2476 self.classes.A,
2477 self.classes.B,
2478 self.tables.b,
2479 self.tables.atob,
2480 )
2481
2482 # if no backref here, delete-orphan failed until [ticket:427]
2483 # was fixed
2484
2485 self.mapper_registry.map_imperatively(
2486 A,
2487 a,
2488 properties={
2489 "bs": relationship(
2490 B,
2491 secondary=atob,
2492 cascade="all, delete-orphan",
2493 single_parent=True,
2494 )
2495 },
2496 )
2497 self.mapper_registry.map_imperatively(B, b)
2498
2499 sess = fixture_session()
2500 b1 = B(data="b1")
2501 a1 = A(data="a1", bs=[b1])
2502 sess.add(a1)
2503 sess.flush()
2504
2505 a1.bs.remove(b1)
2506 sess.flush()
2507 eq_(
2508 sess.execute(select(func.count("*")).select_from(atob)).scalar(), 0
2509 )
2510 eq_(sess.execute(select(func.count("*")).select_from(b)).scalar(), 0)
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 = (

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