MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _annotate_selfref

Method _annotate_selfref

lib/sqlalchemy/orm/relationships.py:2788–2811  ·  view source on GitHub ↗

annotate 'remote' in primaryjoin, secondaryjoin when the relationship is detected as self-referential.

(
        self, fn: Callable[[ColumnElement[Any]], bool], remote_side_given: bool
    )

Source from the content-addressed store, hash-verified

2786 )
2787
2788 def _annotate_selfref(
2789 self, fn: Callable[[ColumnElement[Any]], bool], remote_side_given: bool
2790 ) -> None:
2791 """annotate 'remote' in primaryjoin, secondaryjoin
2792 when the relationship is detected as self-referential.
2793
2794 """
2795
2796 def visit_binary(binary: BinaryExpression[Any]) -> None:
2797 equated = binary.left.compare(binary.right)
2798 if isinstance(binary.left, expression.ColumnClause) and isinstance(
2799 binary.right, expression.ColumnClause
2800 ):
2801 # assume one to many - FKs are "remote"
2802 if fn(binary.left):
2803 binary.left = binary.left._annotate({"remote": True})
2804 if fn(binary.right) and not equated:
2805 binary.right = binary.right._annotate({"remote": True})
2806 elif not remote_side_given:
2807 self._warn_non_column_elements()
2808
2809 self.primaryjoin = visitors.cloned_traverse(
2810 self.primaryjoin, {}, {"binary": visit_binary}
2811 )
2812
2813 def _annotate_remote_from_args(self) -> None:
2814 """annotate 'remote' in primaryjoin, secondaryjoin

Callers 2

_annotate_remoteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected