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

Method test_used_in_relationship

test/orm/test_unitofwork.py:1282–1329  ·  view source on GitHub ↗

A server-side default can be used as the target of a foreign key

(self)

Source from the content-addressed store, hash-verified

1280 eq_(h1.foober, "im the update")
1281
1282 def test_used_in_relationship(self):
1283 """A server-side default can be used as the target of a foreign key"""
1284
1285 Hoho, hohoval, default_t, secondary_table, Secondary = (
1286 self.classes.Hoho,
1287 self.other.hohoval,
1288 self.tables.default_t,
1289 self.tables.secondary_table,
1290 self.classes.Secondary,
1291 )
1292
1293 self.mapper_registry.map_imperatively(
1294 Hoho,
1295 default_t,
1296 properties={
1297 "secondaries": relationship(
1298 Secondary, order_by=secondary_table.c.id
1299 )
1300 },
1301 )
1302 self.mapper_registry.map_imperatively(Secondary, secondary_table)
1303
1304 h1 = Hoho()
1305 s1 = Secondary(data="s1")
1306 h1.secondaries.append(s1)
1307
1308 session = fixture_session()
1309 session.add(h1)
1310 session.flush()
1311 session.expunge_all()
1312
1313 eq_(
1314 session.get(Hoho, h1.id),
1315 Hoho(hoho=hohoval, secondaries=[Secondary(data="s1")]),
1316 )
1317
1318 h1 = session.get(Hoho, h1.id)
1319 h1.secondaries.append(Secondary(data="s2"))
1320 session.flush()
1321 session.expunge_all()
1322
1323 eq_(
1324 session.get(Hoho, h1.id),
1325 Hoho(
1326 hoho=hohoval,
1327 secondaries=[Secondary(data="s1"), Secondary(data="s2")],
1328 ),
1329 )
1330
1331
1332class ColumnPropertyTest(fixtures.MappedTest):

Callers

nothing calls this directly

Calls 11

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
HohoClass · 0.70
SecondaryClass · 0.70
appendMethod · 0.45
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected