MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_delete_orphan_dynamic

Method test_delete_orphan_dynamic

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

Source from the content-addressed store, hash-verified

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

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