Role class

Role model used for authorization and role-based access control.

A Role represents a named permission grouping that can be attached to users through the user/role pivot table.

Example:

final role = Role(name: 'admin');
print(role.name); // admin
Inheritance
Mixed-in types
Available extensions

Constructors

Role({required String name})
Creates a new role with the given name.
Role.fromJson(Map<String, dynamic> json)
Creates a role model from a JSON map.

Properties

createdAt DateTime?
Creation timestamp (UTC).
getter/setter pairinherited
description String?
Optional human-readable description of the role.
getter/setter pair
disk DatabaseDisk
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
id int?
Primary key (auto-incremented by backend).
getter/setter pairinherited
name String
Role name.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updatedAt DateTime?
Last update timestamp (UTC).
getter/setter pairinherited
uuid String?
UUID for cross-backend identification.
getter/setter pairinherited

Methods

attach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Attaches sibling to this model using the given relationship type.
belongsToMany<T extends Model>({required PivotTable<Model, Model> table, DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves many-to-many related models through a pivot table.
belongsToOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves the parent model for an inverse relationship.
delete({DatabaseDisk? disk}) Future<bool>
Deletes the current instance.
inherited
detach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Detaches sibling from this model using the given relationship type.
getInstanceTableName() String
inherited
getInstanceTableSingularName() String
inherited
hasMany<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves all one-to-many related models.
hasOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves a one-to-one related model.
load<T extends Model>(ModelRelationshipType relationship, {PivotTable<Model, Model>? table}) Future<Map<String, dynamic>>

Available on Model, provided by the ModelRelationshipOps extension

Loads a relationship and returns this model serialized with the related data embedded.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save({DatabaseDisk? disk}) Future<bool>
Saves the current instance.
inherited
toJson() Map<String, dynamic>
Serializes the role into its standard JSON representation.
override
toMetaJson() Map<String, dynamic>
Serializes the role into a metadata-oriented JSON map.
override
toString() String
Human-readable string representation.
inherited
update({required Map<String, dynamic> withJson, DatabaseDisk? disk}) Future<bool>
Updates the current instance with new data.
inherited

Operators

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

Static Properties

columnDefinitions Map<String, String>
Database column definitions for persisted roles.
getter/setter pair

Static Methods

admin(HttpRequest request, Future<void> next()) Future
Middleware that restricts access to users with the admin role.