betty.entity.association module

Entity associations.

final class betty.entity.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.entity.association.AssociationRequired

Bases: RuntimeError, Generic

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

__init__(association: _Association[OwnerT, Any], owner: OwnerT, /)
final class betty.entity.association.BidirectionalToManyMultipleTypes

Bases: _ToManyAssociation[OwnerT, AssociateT, MultipleTypesEntityCollection], _BidirectionalAssociation, Generic

A bidirectional \*-to-many entity type association where associates may be of different entity types.

final class betty.entity.association.BidirectionalToManySingleType

Bases: _ToManyAssociation[OwnerT, AssociateT, SingleTypeEntityCollection], _BidirectionalAssociation, Generic

A bidirectional \*-to-many entity type association where all associates are of the same entity type.

final class betty.entity.association.BidirectionalToOne

Bases: _ToOneAssociation, _BidirectionalAssociation, Generic

A bidirectional \*-to-one entity type association.

resolve(owner: OwnerT, /) None

Resolve any associates the owner may have for this association.

final class betty.entity.association.BidirectionalToZeroOrOne

Bases: _ToZeroOrOneAssociation, _BidirectionalAssociation, Generic

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.entity.association.TemporaryToManyResolver

Bases: _TemporaryResolver[Iterable], ToManyResolver, Generic

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.entity.association.TemporaryToOneResolver

Bases: _TemporaryResolver, ToOneResolver, Generic

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.entity.association.TemporaryToZeroOrOneResolver

Bases: _TemporaryResolver[EntityT | None], ToZeroOrOneResolver, Generic

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.entity.association.ToManyResolver

Bases: _Resolver[Iterable], Generic

An object that can resolve to a collection of entities.

class betty.entity.association.ToOneResolver

Bases: _Resolver, Generic

An object that can resolve to an entity.

class betty.entity.association.ToZeroOrOneResolver

Bases: _Resolver[EntityT | None], Generic

An object that can optionally resolve to an entity.

final class betty.entity.association.UnidirectionalToManyMultipleTypes

Bases: _ToManyAssociation[OwnerT, AssociateT, MultipleTypesEntityCollection], Generic

A unidirectional to-many entity type association where associates may be of different entity types.

final class betty.entity.association.UnidirectionalToManySingleType

Bases: _ToManyAssociation[OwnerT, AssociateT, SingleTypeEntityCollection], Generic

A unidirectional to-many entity type association where all associates are of the same entity type.

final class betty.entity.association.UnidirectionalToOne

Bases: _ToOneAssociation, Generic

A unidirectional to-one entity type association.

resolve(owner: OwnerT, /) None

Resolve any associates the owner may have for this association.

final class betty.entity.association.UnidirectionalToZeroOrOne

Bases: _ToZeroOrOneAssociation, Generic

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

resolve(owner: OwnerT, /) None

Resolve any associates the owner may have for this association.

betty.entity.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.