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

Method setup_mappers

test/ext/test_associationproxy.py:946–980  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

944
945 @classmethod
946 def setup_mappers(cls):
947 parents_table, children_table = cls.tables("Parent", "Children")
948
949 class CustomProxy(_AssociationList):
950 def __init__(self, lazy_collection, creator, value_attr, parent):
951 getter, setter = parent._default_getset(lazy_collection)
952 _AssociationList.__init__(
953 self, lazy_collection, creator, getter, setter, parent
954 )
955
956 class Parent(cls.Basic):
957 children = association_proxy(
958 "_children",
959 "name",
960 proxy_factory=CustomProxy,
961 proxy_bulk_set=CustomProxy.extend,
962 )
963
964 def __init__(self, name):
965 self.name = name
966
967 class Child(cls.Basic):
968 def __init__(self, name):
969 self.name = name
970
971 cls.mapper_registry.map_imperatively(
972 Parent,
973 parents_table,
974 properties={
975 "_children": relationship(
976 Child, lazy="joined", collection_class=list
977 )
978 },
979 )
980 cls.mapper_registry.map_imperatively(Child, children_table)
981
982 def test_sequence_ops(self):
983 self._test_sequence_ops()

Callers

nothing calls this directly

Calls 2

relationshipFunction · 0.90
map_imperativelyMethod · 0.80

Tested by

no test coverage detected