betty.model.association module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.model.association module

Entity associations.

final class betty.model.association.AssociationRegistry

  Bases: `object`

  Inspect any known entity type associations.

  classmethod get_all_associations(owner: type | object) → set[_Association[Any, Any]]

    Get all associations for an owner.

  classmethod get_association(owner: type[_OwnerT] | _OwnerT, owner_attr_name: str) → _Association[_OwnerT, Any]

    Get the association for a given owner and attribute name.

exception betty.model.association.AssociationRequired

  Bases: `RuntimeError`

  Raised when an operation cannot be performed because the association in question is required.

  classmethod new(association: _Association[_OwnerT, Any], owner: _OwnerT) → Self

    Create a new instance.

class betty.model.association.BidirectionalToMany

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToManyAssociation`[`_OwnerT`, `_AssociateT`], `_BidirectionalAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional *-to-many entity type association.

class betty.model.association.BidirectionalToOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToOneAssociation`[`_OwnerT`, `_AssociateT`], `_BidirectionalAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional *-to-one entity type association.

  resolve(owner: _OwnerT) → None

    Resolve any associates the owner may have for this association.

class betty.model.association.BidirectionalToZeroOrOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToZeroOrOneAssociation`[`_OwnerT`, `_AssociateT`], `_BidirectionalAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional *-to-zero-or-one entity type association.

  resolve(owner: _OwnerT) → None

    Resolve any associates the owner may have for this association.

class betty.model.association.TemporaryToManyResolver

  Bases: `Generic`[`_EntityT`], `_TemporaryResolver`[`_EntityT`], `ToManyResolver`[`_EntityT`]

  A ‘temporary’ to-many resolver.

  This is helpful to satisfy association requirements in multiple steps. Users MUST ensure that this resolver is replaced by a real value, because the resolver will never be able to resolve itself.

class betty.model.association.TemporaryToOneResolver

  Bases: `Generic`[`_EntityT`], `_TemporaryResolver`[`_EntityT`], `ToOneResolver`[`_EntityT`]

  A ‘temporary’ to-one resolver.

  This is helpful to satisfy association requirements in multiple steps. Users MUST ensure that this resolver is replaced by a real value, because the resolver will never be able to resolve itself.

class betty.model.association.TemporaryToZeroOrOneResolver

  Bases: `Generic`[`_EntityT`], `_TemporaryResolver`[`_EntityT`], `ToZeroOrOneResolver`[`_EntityT`]

  A ‘temporary’ to-zero-or-one resolver.

  This is helpful to satisfy association requirements in multiple steps. Users MUST ensure that this resolver is replaced by a real value, because the resolver will never be able to resolve itself.

class betty.model.association.ToManyResolver

  Bases: `Generic`[`_EntityT`], `_Resolver`[`Iterable`[`_EntityT`]]

  An object that can resolve to a collection of entities.

class betty.model.association.ToOneResolver

  Bases: `Generic`[`_EntityT`], `_Resolver`[`_EntityT`]

  An object that can resolve to an entity.

class betty.model.association.ToZeroOrOneResolver

  Bases: `Generic`[`_EntityT`], `_Resolver`[`_EntityT` | `None`]

  An object that can optionally resolve to an entity.

final class betty.model.association.UnidirectionalToMany

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToManyAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-many entity type association.

final class betty.model.association.UnidirectionalToOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToOneAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-one entity type association.

  resolve(owner: _OwnerT) → None

    Resolve any associates the owner may have for this association.

final class betty.model.association.UnidirectionalToZeroOrOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_ToZeroOrOneAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-zero-or-one entity type association.

  resolve(owner: _OwnerT) → None

    Resolve any associates the owner may have for this association.

betty.model.association.resolve(*entities: Entity) → None

  Resolve all entities’ associates.

  You MUST call this on all entities once the resolvers you have set on them can indeed be resolved.