MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_basic

Method test_basic

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

Source from the content-addressed store, hash-verified

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