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

Method test_basic

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

Source from the content-addressed store, hash-verified

3581 )
3582
3583 def test_basic(self):
3584 table_b, table_a = self.tables.table_b, self.tables.table_a
3585
3586 class A(ComparableEntity):
3587 pass
3588
3589 class B(ComparableEntity):
3590 pass
3591
3592 self.mapper_registry.map_imperatively(
3593 A,
3594 table_a,
3595 properties={"bs": relationship(B, cascade="all, delete-orphan")},
3596 )
3597 self.mapper_registry.map_imperatively(B, table_b)
3598
3599 a1 = A(name="a1", bs=[B(name="b1"), B(name="b2"), B(name="b3")])
3600
3601 sess = fixture_session()
3602 sess.add(a1)
3603 sess.flush()
3604
3605 sess.expunge_all()
3606
3607 eq_(
3608 sess.get(A, a1.id),
3609 A(name="a1", bs=[B(name="b1"), B(name="b2"), B(name="b3")]),
3610 )
3611
3612 a1 = sess.get(A, a1.id)
3613 assert not class_mapper(B)._is_orphan(
3614 attributes.instance_state(a1.bs[0])
3615 )
3616 a1.bs[0].foo = "b2modified"
3617 a1.bs[1].foo = "b3modified"
3618 sess.flush()
3619
3620 sess.expunge_all()
3621 eq_(
3622 sess.get(A, a1.id),
3623 A(name="a1", bs=[B(name="b1"), B(name="b2"), B(name="b3")]),
3624 )
3625
3626
3627class OrphanCriterionTest(fixtures.MappedTest):

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
class_mapperFunction · 0.90
map_imperativelyMethod · 0.80
_is_orphanMethod · 0.80
AClass · 0.70
BClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected