MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / SynonymProperty

Class SynonymProperty

lib/sqlalchemy/orm/descriptor_props.py:995–1165  ·  view source on GitHub ↗

Denote an attribute name as a synonym to a mapped property, in that the attribute will mirror the value and expression behavior of another attribute. :class:`.Synonym` is constructed using the :func:`_orm.synonym` function. .. seealso:: :ref:`synonyms` - Overview of sy

Source from the content-addressed store, hash-verified

993
994
995class SynonymProperty(DescriptorProperty[_T]):
996 """Denote an attribute name as a synonym to a mapped property,
997 in that the attribute will mirror the value and expression behavior
998 of another attribute.
999
1000 :class:`.Synonym` is constructed using the :func:`_orm.synonym`
1001 function.
1002
1003 .. seealso::
1004
1005 :ref:`synonyms` - Overview of synonyms
1006
1007 """
1008
1009 comparator_factory: Optional[Type[PropComparator[_T]]]
1010
1011 def __init__(
1012 self,
1013 name: str,
1014 map_column: Optional[bool] = None,
1015 descriptor: Optional[Any] = None,
1016 comparator_factory: Optional[Type[PropComparator[_T]]] = None,
1017 attribute_options: Optional[_AttributeOptions] = None,
1018 info: Optional[_InfoType] = None,
1019 doc: Optional[str] = None,
1020 ):
1021 super().__init__(attribute_options=attribute_options)
1022
1023 self.name = name
1024 self.map_column = map_column
1025 self.descriptor = descriptor
1026 self.comparator_factory = comparator_factory
1027 if doc:
1028 self.doc = doc
1029 elif descriptor and descriptor.__doc__:
1030 self.doc = descriptor.__doc__
1031 else:
1032 self.doc = None
1033 if info:
1034 self.info.update(info)
1035
1036 util.set_creation_order(self)
1037
1038 if not TYPE_CHECKING:
1039
1040 @property
1041 def uses_objects(self) -> bool:
1042 return getattr(self.parent.class_, self.name).impl.uses_objects
1043
1044 # TODO: when initialized, check _proxied_object,
1045 # emit a warning if its not a column-based property
1046
1047 @util.memoized_property
1048 def _proxied_object(
1049 self,
1050 ) -> Union[MapperProperty[_T], SQLORMOperations[_T]]:
1051 attr = getattr(self.parent.class_, self.name)
1052 if not hasattr(attr, "property") or not isinstance(

Callers 2

_add_attributeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected