betty.model.association module

Entity associations.

class betty.model.association.Association[source]

Bases: Generic[_OwnerT, _AssociateT]

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

Get all associations for an owner.

classmethod get_associates(owner: _EntityT, association: Association[_EntityT, _AssociateT]) Iterable[_AssociateT & Entity][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][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.

class betty.model.association.ToManyAssociation[source]

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

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.

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

Disassociate two entities.

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]

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.

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

Disassociate two entities.