MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_onetoone_switch

Method test_onetoone_switch

test/orm/test_relationships.py:1613–1646  ·  view source on GitHub ↗

test that active history is enabled on a one-to-many/one that has use_get==True

(self)

Source from the content-addressed store, hash-verified

1611 pass
1612
1613 def test_onetoone_switch(self):
1614 """test that active history is enabled on a
1615 one-to-many/one that has use_get==True"""
1616
1617 tableB, A, B, tableA = (
1618 self.tables.tableB,
1619 self.classes.A,
1620 self.classes.B,
1621 self.tables.tableA,
1622 )
1623
1624 self.mapper_registry.map_imperatively(
1625 A,
1626 tableA,
1627 properties={
1628 "b": relationship(
1629 B, cascade="all,delete-orphan", uselist=False
1630 )
1631 },
1632 )
1633 self.mapper_registry.map_imperatively(B, tableB)
1634
1635 configure_mappers()
1636 assert A.b.property.strategy.use_get
1637
1638 with fixture_session() as sess:
1639 a1 = A()
1640 sess.add(a1)
1641 sess.commit()
1642
1643 with fixture_session() as sess:
1644 a1 = sess.query(A).first()
1645 a1.b = B()
1646 sess.commit()
1647
1648 def test_no_delete_PK_AtoB(self):
1649 """A can't be deleted without B because B would have no PK value."""

Callers

nothing calls this directly

Calls 10

relationshipFunction · 0.90
configure_mappersFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
AClass · 0.70
BClass · 0.70
addMethod · 0.45
commitMethod · 0.45
firstMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected