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

Class SynonymProperty

lib/sqlalchemy/orm/descriptor_props.py:939–1074  ·  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

937
938
939class SynonymProperty(DescriptorProperty[_T]):
940 """Denote an attribute name as a synonym to a mapped property,
941 in that the attribute will mirror the value and expression behavior
942 of another attribute.
943
944 :class:`.Synonym` is constructed using the :func:`_orm.synonym`
945 function.
946
947 .. seealso::
948
949 :ref:`synonyms` - Overview of synonyms
950
951 """
952
953 comparator_factory: Optional[Type[PropComparator[_T]]]
954
955 def __init__(
956 self,
957 name: str,
958 map_column: Optional[bool] = None,
959 descriptor: Optional[Any] = None,
960 comparator_factory: Optional[Type[PropComparator[_T]]] = None,
961 attribute_options: Optional[_AttributeOptions] = None,
962 info: Optional[_InfoType] = None,
963 doc: Optional[str] = None,
964 ):
965 super().__init__(attribute_options=attribute_options)
966
967 self.name = name
968 self.map_column = map_column
969 self.descriptor = descriptor
970 self.comparator_factory = comparator_factory
971 if doc:
972 self.doc = doc
973 elif descriptor and descriptor.__doc__:
974 self.doc = descriptor.__doc__
975 else:
976 self.doc = None
977 if info:
978 self.info.update(info)
979
980 util.set_creation_order(self)
981
982 if not TYPE_CHECKING:
983
984 @property
985 def uses_objects(self) -> bool:
986 return getattr(self.parent.class_, self.name).impl.uses_objects
987
988 # TODO: when initialized, check _proxied_object,
989 # emit a warning if its not a column-based property
990
991 @util.memoized_property
992 def _proxied_object(
993 self,
994 ) -> Union[MapperProperty[_T], SQLORMOperations[_T]]:
995 attr = getattr(self.parent.class_, self.name)
996 if not hasattr(attr, "property") or not isinstance(

Callers 2

_add_attributeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected