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

Method setup_mappers

test/orm/test_composites.py:1307–1350  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

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