betty.model.association module

Entity associations.

class betty.model.association.Association[source]

Bases: Generic[_OwnerT, _AssociateT, _AssociationAttrValueT, _AssociationAttrSetT], MutableAttr[Intersection[_OwnerT, Entity], _AssociationAttrValueT, _AssociationAttrSetT]

Define an association between two entity types.

__init__(owner_type_name: str, owner_attr_name: str, associate_type_name: str)[source]
abstract associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Associate two entities.

property associate_type: type[_AssociateT]

The type of any associate entities.

abstract disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Disassociate two entities.

property owner_attr_name: str

The name of the attribute on the owning entity that contains this association.

property owner_type: type[_OwnerT]

The type of the owning entity that contains this association.

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

Get all associations for an owner.

classmethod get_associates(owner: _EntityT, association: Association[_EntityT, _AssociateT, Any, Any]) Iterable[_AssociateT][source]

Get the associates for a given owner and association.

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

Get the association for a given owner and attribute name.

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

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

A bidirectional many-to-many entity type association.

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

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

A bidirectional many-to-one entity type association.

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

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

A bidirectional one-to-many entity type association.

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

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

A bidirectional one-to-one entity type association.

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

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

A unidirectional to-many entity type association.

new_attr(instance: _OwnerT & Entity) EntityCollection[_AssociateT][source]

Create a new attribute value.

class betty.model.association.ToManyAssociation[source]

Bases: Generic[_OwnerT, _AssociateT], Association[_OwnerT, _AssociateT, EntityCollection[_AssociateT], Iterable[Intersection[_AssociateT, Entity]]]

A to-many entity type association.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Associate two entities.

del_attr(instance: _OwnerT & Entity) None[source]

Delete the attribute value.

disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Disassociate two entities.

set_attr(instance: _OwnerT & Entity, value: Iterable[Intersection[_AssociateT, Entity]]) None[source]

Set the associates on the given owner.

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

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

A unidirectional to-one entity type association.

class betty.model.association.ToOneAssociation[source]

Bases: Generic[_OwnerT, _AssociateT], Association[_OwnerT, _AssociateT, Intersection[_AssociateT, Entity] | None, Intersection[_AssociateT, Entity] | None]

A unidirectional to-one entity type association.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Associate two entities.

del_attr(instance: _OwnerT & Entity) None[source]

Delete the attribute value.

disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None[source]

Disassociate two entities.

new_attr(instance: _OwnerT & Entity) None[source]

Create a new attribute value.

set_attr(instance: _OwnerT & Entity, value: Intersection[_AssociateT, Entity] | None) None[source]

Set the attribute value.