betty.model.association module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.model.association module

Entity associations.

class betty.model.association.Association

  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)
  abstract associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None

    Associate two entities.

  property associate_type: type[_AssociateT]

    The type of any associate entities.

  abstract disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None

    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

  Bases: `object`

  Inspect any known entity type associations.

  classmethod get_all_associations(owner: type | object) → set[Association[Any, Any, Any, Any]]

    Get all associations for an owner.

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

    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]

    Get the association for a given owner and attribute name.

final class betty.model.association.ManyToMany

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

  A bidirectional many-to-many entity type association.

final class betty.model.association.ManyToOne

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

  A bidirectional many-to-one entity type association.

final class betty.model.association.OneToMany

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

  A bidirectional one-to-many entity type association.

final class betty.model.association.OneToOne

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

  A bidirectional one-to-one entity type association.

final class betty.model.association.ToMany

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

  A unidirectional to-many entity type association.

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

    Create a new attribute value.

class betty.model.association.ToManyAssociation

  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

    Associate two entities.

  del_attr(instance: _OwnerT & Entity) → None

    Delete the attribute value.

  disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None

    Disassociate two entities.

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

    Set the associates on the given owner.

final class betty.model.association.ToOne

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

  A unidirectional to-one entity type association.

class betty.model.association.ToOneAssociation

  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

    Associate two entities.

  del_attr(instance: _OwnerT & Entity) → None

    Delete the attribute value.

  disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None

    Disassociate two entities.

  new_attr(instance: _OwnerT & Entity) → None

    Create a new attribute value.

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

    Set the attribute value.