MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_backref

Method test_backref

test/orm/test_unitofwork.py:59–89  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

57 pass
58
59 def test_backref(self):
60 Address, addresses, users, User = (
61 self.classes.Address,
62 self.tables.addresses,
63 self.tables.users,
64 self.classes.User,
65 )
66
67 am = self.mapper_registry.map_imperatively(Address, addresses)
68 m = self.mapper_registry.map_imperatively(
69 User,
70 users,
71 properties=dict(
72 addresses=relationship(am, backref="user", lazy="joined")
73 ),
74 )
75
76 session = fixture_session()
77
78 u = User(name="u1")
79 a = Address(email_address="u1@e")
80 a.user = u
81 session.add(u)
82
83 eq_(u.addresses, [a])
84 session.commit()
85 session.expunge_all()
86
87 u = session.query(m).one()
88 assert u.addresses[0].user == u
89 session.close()
90
91
92class UnicodeTest(fixtures.MappedTest):

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
UserClass · 0.70
AddressClass · 0.70
addMethod · 0.45
commitMethod · 0.45
expunge_allMethod · 0.45
oneMethod · 0.45
queryMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected