MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / set_parent

Method set_parent

lib/sqlalchemy/orm/descriptor_props.py:1130–1165  ·  view source on GitHub ↗
(self, parent: Mapper[Any], init: bool)

Source from the content-addressed store, hash-verified

1128
1129 @util.preload_module("sqlalchemy.orm.properties")
1130 def set_parent(self, parent: Mapper[Any], init: bool) -> None:
1131 properties = util.preloaded.orm_properties
1132
1133 if self.map_column:
1134 # implement the 'map_column' option.
1135 if self.key not in parent.persist_selectable.c:
1136 raise sa_exc.ArgumentError(
1137 "Can't compile synonym '%s': no column on table "
1138 "'%s' named '%s'"
1139 % (
1140 self.name,
1141 parent.persist_selectable.description,
1142 self.key,
1143 )
1144 )
1145 elif (
1146 parent.persist_selectable.c[self.key]
1147 in parent._columntoproperty
1148 and parent._columntoproperty[
1149 parent.persist_selectable.c[self.key]
1150 ].key
1151 == self.name
1152 ):
1153 raise sa_exc.ArgumentError(
1154 "Can't call map_column=True for synonym %r=%r, "
1155 "a ColumnProperty already exists keyed to the name "
1156 "%r for column %r"
1157 % (self.key, self.name, self.name, self.key)
1158 )
1159 p: ColumnProperty[Any] = properties.ColumnProperty(
1160 parent.persist_selectable.c[self.key]
1161 )
1162 parent._configure_property(self.name, p, init=init, setparent=True)
1163 p._mapped_by_synonym = self.key
1164
1165 self.parent = parent
1166
1167
1168class Synonym(SynonymProperty[_T], _DeclarativeMapped[_T]):

Callers

nothing calls this directly

Calls 1

_configure_propertyMethod · 0.80

Tested by

no test coverage detected