MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/orm/strategies.py:730–785  ·  view source on GitHub ↗
(
        self, parent: RelationshipProperty[Any], strategy_key: Tuple[Any, ...]
    )

Source from the content-addressed store, hash-verified

728 parent_property: RelationshipProperty[Any]
729
730 def __init__(
731 self, parent: RelationshipProperty[Any], strategy_key: Tuple[Any, ...]
732 ):
733 super().__init__(parent, strategy_key)
734 self._raise_always = self.strategy_opts["lazy"] == "raise"
735 self._raise_on_sql = self.strategy_opts["lazy"] == "raise_on_sql"
736
737 self.is_aliased_class = inspect(self.entity).is_aliased_class
738
739 join_condition = self.parent_property._join_condition
740 (
741 self._lazywhere,
742 self._bind_to_col,
743 self._equated_columns,
744 ) = join_condition.create_lazy_clause()
745
746 (
747 self._rev_lazywhere,
748 self._rev_bind_to_col,
749 self._rev_equated_columns,
750 ) = join_condition.create_lazy_clause(reverse_direction=True)
751
752 if self.parent_property.order_by:
753 self._order_by = util.to_list(self.parent_property.order_by)
754 else:
755 self._order_by = None
756
757 self.logger.info("%s lazy loading clause %s", self, self._lazywhere)
758
759 # determine if our "lazywhere" clause is the same as the mapper's
760 # get() clause. then we can just use mapper.get()
761 #
762 # TODO: the "not self.uselist" can be taken out entirely; a m2o
763 # load that populates for a list (very unusual, but is possible with
764 # the API) can still set for "None" and the attribute system will
765 # populate as an empty list.
766 self.use_get = (
767 not self.is_aliased_class
768 and not self.uselist
769 and self.entity._get_clause[0].compare(
770 self._lazywhere,
771 use_proxies=True,
772 compare_keys=False,
773 equivalents=self.mapper._equivalent_columns,
774 )
775 )
776
777 if self.use_get:
778 for col in list(self._equated_columns):
779 if col in self.mapper._equivalent_columns:
780 for c in self.mapper._equivalent_columns[col]:
781 self._equated_columns[c] = self._equated_columns[col]
782
783 self.logger.info(
784 "%s will use Session.get() to optimize instance loads", self
785 )
786
787 def init_class_attribute(self, mapper):

Callers 9

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 4

inspectFunction · 0.90
create_lazy_clauseMethod · 0.80
infoMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected