RelationalDatumEntityMixin mixin

A mixin that provides relational functionality for Datum entities.

Use this mixin when you want to compose Datum's relational capabilities into your own base classes, allowing for a clean and maintainable architecture without extending RelationalDatumEntity.

Important: Use either DatumEntityMixin OR RelationalDatumEntityMixin, not both. RelationalDatumEntityMixin provides all the functionality of DatumEntityMixin plus relational capabilities.

class MyEntity with RelationalDatumEntityMixin {
  @override
  final String id;
  @override
  final String userId;
  @override
  final DateTime modifiedAt;
  @override
  final DateTime createdAt;
  @override
  final int version;
  @override
  final bool isDeleted;

  // Your custom fields...

  @override
  Map<String, Relation> get relations => {
    'author': BelongsTo<User>(this, 'userId'),
  };

  @override
  Map<String, dynamic> toDatumMap({MapTarget target = MapTarget.local}) {
    // Implementation...
  }

  @override
  DatumEntityInterface copyWith({DateTime? modifiedAt, int? version, bool? isDeleted}) {
    // Implementation...
  }

  @override
  Map<String, dynamic>? diff(covariant DatumEntityInterface oldVersion) {
    // Implementation...
  }
}
Implemented types
Mixin applications

Properties

createdAt → DateTime
The timestamp of when this entity was first created.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
id → String
A unique identifier for the entity.
no setteroverride
isDeleted → bool
A flag indicating if this entity has been locally marked for deletion.
no setteroverride
isRelational → bool
Indicates whether this entity supports relationships. Always true for this mixin.
no setteroverride
modifiedAt → DateTime
The timestamp of the last time this entity was modified.
no setteroverride
props → List<Object?>
Provides the list of properties to be used by the Equatable mixin for value equality checks.
no setter
relations → Map<String, Relation<DatumEntityInterface>>
A map defining all relationships for this entity.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stringify → bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
userId → String
The ID of the user who owns or created this entity.
no setteroverride
vectorClock → VectorClock?
A vector clock for tracking causality across multiple devices.
no setteroverride
version → int
A sequential integer used for optimistic concurrency and tracking changes.
no setteroverride

Methods

diff(covariant DatumEntityInterface oldVersion) → Map<String, dynamic>?
Computes the difference between the current entity state and an oldVersion of the entity.
override
incrementClock(String replicaId) → DatumEntityInterface
Returns a new instance with the vector clock incremented for replicaId.
override
merge(covariant DatumEntityInterface other) → DatumEntityInterface
Merges this entity with other.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDatumMap({MapTarget target = MapTarget.local}) → Map<String, dynamic>
Converts the entity to a Map<String, dynamic> for persistence.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited