MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / for_class

Method for_class

lib/sqlalchemy/ext/associationproxy.py:465–495  ·  view source on GitHub ↗

r"""Return the internal state local to a specific mapped class. E.g., given a class ``User``:: class User(Base): # ... keywords = association_proxy("kws", "keyword") If we access this :class:`.AssociationProxy` from :attr:`_orm.

(
        self, class_: Type[Any], obj: Optional[object] = None
    )

Source from the content-addressed store, hash-verified

463 self._as_instance(class_, instance).delete(instance)
464
465 def for_class(
466 self, class_: Type[Any], obj: Optional[object] = None
467 ) -> AssociationProxyInstance[_T]:
468 r"""Return the internal state local to a specific mapped class.
469
470 E.g., given a class ``User``::
471
472 class User(Base):
473 # ...
474
475 keywords = association_proxy("kws", "keyword")
476
477 If we access this :class:`.AssociationProxy` from
478 :attr:`_orm.Mapper.all_orm_descriptors`, and we want to view the
479 target class for this proxy as mapped by ``User``::
480
481 inspect(User).all_orm_descriptors["keywords"].for_class(User).target_class
482
483 This returns an instance of :class:`.AssociationProxyInstance` that
484 is specific to the ``User`` class. The :class:`.AssociationProxy`
485 object remains agnostic of its parent class.
486
487 :param class\_: the class that we are returning state for.
488
489 :param obj: optional, an instance of the class that is required
490 if the attribute refers to a polymorphic target, e.g. where we have
491 to look at the type of the actual destination object to get the
492 complete path.
493
494 """
495 return self._as_instance(class_, obj)
496
497 def _as_instance(
498 self, class_: Any, obj: Any

Callers 1

Calls 1

_as_instanceMethod · 0.95

Tested by 1