MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_delete_orphan

Method test_delete_orphan

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

Source from the content-addressed store, hash-verified

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