UuidPrimaryKey<T> mixin

Mixin that adds UUID primary key support to models

Automatically generates a UUID when creating a new model. Use with ModelObserver to auto-generate on creation.

Example:

class User extends KhademModel<User> with UuidPrimaryKey {
  // The uuid field will be auto-generated
}

// With observer for auto-generation:
class UserObserver extends ModelObserver<User> {
  @override
  void creating(User user) {
    user.ensureUuidGenerated();
  }
}

// Manual generation:
final user = User();
user.generateUuid();
print(user.uuid); // "550e8400-e29b-41d4-a716-446655440000"
Superclass constraints

Properties

appends Map<String, dynamic>
The accessors to append to the model's array form.
no setterinherited
attributes Map<String, dynamic>
Get all of the current attributes on the model.
no setterinherited
casts Map<String, dynamic>
The attributes that should be cast to native types.
no setterinherited
exists bool
getter/setter pairinherited
fillable List<String>
The attributes that are mass assignable.
no setterinherited
guarded List<String>
The attributes that aren't mass assignable.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
hasUuid bool
Check if UUID has been generated
no setter
hidden List<String>
The attributes that should be hidden for serialization.
no setterinherited
id int?
getter/setter pairinherited
original Map<String, dynamic>
Get the original attributes.
no setterinherited
primaryKey String
no setterinherited
query QueryBuilderInterface<T>
Get a new query builder for the model's table.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
table String
no setterinherited
tableName String
no setterinherited
uuid String?
The UUID value
getter/setter pair
uuidColumn String
The UUID column name
no setter
visible List<String>
The attributes that should be visible in serialization.
no setterinherited

Methods

all() Future<List<T>>
Get all models.
inherited
append(List<String> attributes) → void
Append attributes.
inherited
castAttribute(String key, dynamic value) → dynamic
Cast an attribute to its declared Dart type.
inherited
decrement(String column, [int amount = 1]) Future<void>
Decrement a column's value.
inherited
delete() Future<bool>
Delete the model from the database.
inherited
ensureUuidGenerated() → void
Generate UUID only if not already set
except(List<String> keys) Map<String, dynamic>
Get all attributes except the given keys.
inherited
fill(Map<String, dynamic> attributes) → T
Fill the model with an array of attributes.
inherited
find(dynamic id) Future<T?>
Find a model by its primary key.
inherited
findOrFail(dynamic id) Future<T>
Find a model by its primary key or throw an exception.
inherited
forceFill(Map<String, dynamic> attributes) → T
Force fill the model with an array of attributes.
inherited
fresh([List<String> withRelations = const []]) Future<T?>
Get a fresh instance of the model from the database.
inherited
fromJson(Map<String, dynamic> json) → void
Initialize from database record
inherited
generateUuid() → void
Generate a new UUID v4
getAttribute(String key) → dynamic
Get an attribute from the model.
inherited
getDirty() Map<String, dynamic>
Get the attributes that have been changed since the last sync.
inherited
getKey() → dynamic
inherited
getOrGenerateUuid() String
Get UUID or generate if missing
getOriginal(String key, [dynamic defaultValue]) → dynamic
Get an original attribute value.
inherited
getRawAttribute(String key, [dynamic defaultValue]) → dynamic
Get a raw attribute without casting.
inherited
hasAttribute(String key) bool
Check if the model has a specific attribute.
inherited
hasCast(String key) bool
Determine if an attribute has a cast.
inherited
hasOriginal(String key) bool
Check if the model has a specific original attribute.
inherited
increment(String column, [int amount = 1]) Future<void>
Increment a column's value.
inherited
isClean([dynamic attributes]) bool
Check if the model or specific attribute is clean.
inherited
isDirty([dynamic attributes]) bool
Check if the model or specific attribute is dirty.
inherited
isFillable(String key) bool
Determine if the given attribute may be mass assigned.
inherited
makeHidden(List<String> attributes) → void
Make attributes hidden.
inherited
makeVisible(List<String> attributes) → void
Make attributes visible.
inherited
mergeAttributes(Map<String, dynamic> attributes) → void
Merge new attributes into the model.
inherited
newFactory(Map<String, dynamic> data) → T
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
only(List<String> keys) Map<String, dynamic>
Get a subset of attributes.
inherited
refresh() Future<void>
Refresh the model from the database.
inherited
save() Future<bool>
Auto-generate UUID on create
override
setAttribute(String key, dynamic value) → void
Set a given attribute on the model.
inherited
setRawAttribute(String key, dynamic value) → void
Set a raw attribute without casting.
inherited
syncOriginal() → void
Sync the original attributes with the current.
inherited
toDatabaseMap() Map<String, dynamic>
Prepare the model for database insertion/update.
inherited
toJson() Map<String, dynamic>
Convert the model instance to JSON.
inherited
toJsonAsync() Future<Map<String, dynamic>>
inherited
toMap() Map<String, dynamic>
Convert the model instance to a map.
inherited
toMapAsync() Future<Map<String, dynamic>>
Convert the model instance to a map, resolving any Future values.
inherited
toString() String
A string representation of this object.
inherited
update(Map<String, dynamic> attributes) Future<bool>
Update the model in the database.
inherited

Operators

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