Assemble a that can load the columns local to this subclass as a SELECT with IN.
(self, entity, polymorphic_from)
| 3801 | |
| 3802 | @util.preload_module("sqlalchemy.orm.strategy_options") |
| 3803 | def _subclass_load_via_in(self, entity, polymorphic_from): |
| 3804 | """Assemble a that can load the columns local to |
| 3805 | this subclass as a SELECT with IN. |
| 3806 | |
| 3807 | """ |
| 3808 | |
| 3809 | strategy_options = util.preloaded.orm_strategy_options |
| 3810 | |
| 3811 | assert self.inherits |
| 3812 | |
| 3813 | if self.polymorphic_on is not None: |
| 3814 | polymorphic_prop = self._columntoproperty[self.polymorphic_on] |
| 3815 | keep_props = set([polymorphic_prop] + self._identity_key_props) |
| 3816 | else: |
| 3817 | keep_props = set(self._identity_key_props) |
| 3818 | |
| 3819 | disable_opt = strategy_options.Load(entity) |
| 3820 | enable_opt = strategy_options.Load(entity) |
| 3821 | |
| 3822 | classes_to_include = {self} |
| 3823 | m: Optional[Mapper[Any]] = self.inherits |
| 3824 | while ( |
| 3825 | m is not None |
| 3826 | and m is not polymorphic_from |
| 3827 | and m.polymorphic_load == "selectin" |
| 3828 | ): |
| 3829 | classes_to_include.add(m) |
| 3830 | m = m.inherits |
| 3831 | |
| 3832 | for prop in self.column_attrs + self.relationships: |
| 3833 | # skip prop keys that are not instrumented on the mapped class. |
| 3834 | # this is primarily the "_sa_polymorphic_on" property that gets |
| 3835 | # created for an ad-hoc polymorphic_on SQL expression, issue #8704 |
| 3836 | if prop.key not in self.class_manager: |
| 3837 | continue |
| 3838 | |
| 3839 | if prop.parent in classes_to_include or prop in keep_props: |
| 3840 | # "enable" options, to turn on the properties that we want to |
| 3841 | # load by default (subject to options from the query) |
| 3842 | if not isinstance(prop, StrategizedProperty): |
| 3843 | continue |
| 3844 | |
| 3845 | enable_opt = enable_opt._set_generic_strategy( |
| 3846 | # convert string name to an attribute before passing |
| 3847 | # to loader strategy. note this must be in terms |
| 3848 | # of given entity, such as AliasedClass, etc. |
| 3849 | (getattr(entity.entity_namespace, prop.key),), |
| 3850 | dict(prop.strategy_key), |
| 3851 | _reconcile_to_other=True, |
| 3852 | ) |
| 3853 | else: |
| 3854 | # "disable" options, to turn off the properties from the |
| 3855 | # superclass that we *don't* want to load, applied after |
| 3856 | # the options from the query to override them |
| 3857 | disable_opt = disable_opt._set_generic_strategy( |
| 3858 | # convert string name to an attribute before passing |
| 3859 | # to loader strategy. note this must be in terms |
| 3860 | # of given entity, such as AliasedClass, etc. |
no test coverage detected