betty.model.association module

Entity associations.

final class betty.model.association.AssociationRegistry[source]

Bases: object

Inspect any known entity type associations.

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

Get all associations for an owner.

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

Get the association for a given owner and attribute name.

exception betty.model.association.AssociationRequired[source]

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[source]

Create a new instance.

class betty.model.association.BidirectionalToMany[source]

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

A bidirectional *-to-many entity type association.

class betty.model.association.BidirectionalToOne[source]

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

A bidirectional *-to-one entity type association.

resolve(owner: _OwnerT) None[source]

Resolve any associates the owner may have for this association.

class betty.model.association.BidirectionalToZeroOrOne[source]

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

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

resolve(owner: _OwnerT) None[source]

Resolve any associates the owner may have for this association.

class betty.model.association.TemporaryToManyResolver[source]

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[source]

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[source]

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[source]

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

An object that can resolve to a collection of entities.

class betty.model.association.ToOneResolver[source]

Bases: Generic[_EntityT], _Resolver[_EntityT]

An object that can resolve to an entity.

class betty.model.association.ToZeroOrOneResolver[source]

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

An object that can optionally resolve to an entity.

final class betty.model.association.UnidirectionalToMany[source]

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

A unidirectional to-many entity type association.

final class betty.model.association.UnidirectionalToOne[source]

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

A unidirectional to-one entity type association.

resolve(owner: _OwnerT) None[source]

Resolve any associates the owner may have for this association.

final class betty.model.association.UnidirectionalToZeroOrOne[source]

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

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

resolve(owner: _OwnerT) None[source]

Resolve any associates the owner may have for this association.

betty.model.association.resolve(*entities: Entity) None[source]

Resolve all entities’ associates.

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