anymodel.types.entity

Entity base class and state management.

This module provides the Entity base class for domain objects and the MappingState class for tracking entity persistence state.

Classes

class anymodel.types.entity.Entity(**data)[source]

Bases: BaseModel

Base class for domain entities.

Extends Pydantic’s BaseModel with state tracking capabilities for use with the data mapper pattern. Entities track their modification state and storage identity.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class anymodel.types.entity.MappingState(entity)[source]

Bases: object

Tracks the persistence state of an entity.

Manages whether an entity is transient, dirty, or clean, and maintains the entity’s identity in the storage system.

__init__(entity)[source]
property transient

is the related entity transiant, aka not mapped to anything (yet)?

property dirty

is the entity modified since the last clean state (from storage or defaults)?

property clean

is the entity clean? (aka not modified since last save)

property identity
property store
detach()[source]
set_clean()[source]