betty.association module#

Entity associations.

class betty.association.Association#

Bases: LinkedDataDumper[OwnerT, Schema, PortableData], Attr, Generic

An entity association.

__init__(field: FieldDefinition[OwnerT, GetT, DataDefinitionT] | ResolvableDataDefinition[DataDefinitionT], associate: type[AssociateT] | str, associate_attr: Association[AssociateT, OwnerT, Any, Any] | str | None = None, /, *args: Any, **kwargs: Any)#
final assert_not_resolver(owner: OwnerT, value: T, /) Intersection[T, Not[AssociateResolver]]#
final assert_not_resolver(owner: OwnerT, value: Any, /) Never

Assert that a value is not an entity (associate) resolver.

Raises:

UnresolvedAssociate

abstractmethod associate(owner: OwnerT, associate: AssociateT, /) None#

Associate two entities.

property associate_attr: Association[AssociateT, OwnerT, Any, Any] | None#

Get the inverse association, if this association is bidirectional.

property associate_type: type[AssociateT]#

The type of any associate entities.

This may be an abstract class.

abstractmethod disassociate(owner: OwnerT, associate: AssociateT, /) None#

Disassociate two entities.

abstractmethod get_associates(owner: OwnerT, /) Iterable[AssociateT]#

Get the associates for the given owner.

abstractmethod is_resolver(value: Associate[OwnerT, AssociateT], /) TypeGuard[AssociateResolver[OwnerT, AssociateT]]#

Test that the value is an entity (associate) resolver.

abstractmethod resolve(project: Project, owner: OwnerT, /) None#

Resolve any associates the owner may have for this association.

final class betty.association.BiResolver#

Bases: Generic

Wrap another entity (associate) resolver to bidirectionally associate the owner with the resolved associate.

__init__(resolver: AssociateResolver[OwnerT, AssociateT], /)#
final exception betty.association.UnresolvedAssociate#

Bases: ValueError

Raised when an entity (associate) resolver is encountered unexpectedly.

__init__(owner: OwnerT, association: Association[OwnerT, AssociateT, Any, Any, DataDefinition], resolver: AssociateResolver, /)#
betty.association.resolve_associate(project: Project, owner: OwnerT, association: Association[OwnerT, AssociateT], resolver: AssociateResolver[OwnerT, AssociateT], /) AssociateT#

Resolve an associate resolver.

betty.association.resolve_associates(project: Project, *owners: Entity) None#

Resolve all entities’ associates.