MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / setup_mappers

Method setup_mappers

test/orm/test_composites.py:1308–1351  ·  test/orm/test_composites.py::MappedSelectTest.setup_mappers
(cls)

Source from the content-addressed store, hash-verified

1306
1307 @classmethod
1308 def setup_mappers(cls):
1309 values, descriptions = cls.tables.values, cls.tables.descriptions
1310
1311 class Descriptions(cls.Comparable):
1312 pass
1313
1314 class Values(cls.Comparable):
1315 pass
1316
1317 class CustomValues(cls.Comparable, list):
1318 def __init__(self, *args):
1319 self.extend(args)
1320
1321 def __composite_values__(self):
1322 return self
1323
1324 desc_values = (
1325 select(values, descriptions.c.d1, descriptions.c.d2)
1326 .where(
1327 descriptions.c.id == values.c.description_id,
1328 )
1329 .alias(class="st">"descriptions_values")
1330 )
1331
1332 cls.mapper_registry.map_imperatively(
1333 Descriptions,
1334 descriptions,
1335 properties={
1336 class="st">"values": relationship(Values, lazy=class="st">"dynamic"),
1337 class="st">"custom_descriptions": composite(
1338 CustomValues, descriptions.c.d1, descriptions.c.d2
1339 ),
1340 },
1341 )
1342
1343 cls.mapper_registry.map_imperatively(
1344 Values,
1345 desc_values,
1346 properties={
1347 class="st">"custom_values": composite(
1348 CustomValues, desc_values.c.v1, desc_values.c.v2
1349 )
1350 },
1351 )
1352
1353 def test_set_composite_attrs_via_selectable(self, connection):
1354 Values, CustomValues, values, Descriptions, descriptions = (

Callers

nothing calls this directly

Calls 6

selectFunction · 0.90
relationshipFunction · 0.90
compositeFunction · 0.90
map_imperativelyMethod · 0.80
aliasMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected