UniqueRule class

Validates that a value is unique in a database table.

Signature: unique:table,column,except,idColumn,extraCol,extraVal...

Examples:

  • unique:users,email - Email must be unique in users table.
  • unique:users,email,1 - Email unique, ignoring id 1.
  • unique:users,email,1,user_id - Email unique, ignoring user_id 1.
  • unique:users,email,NULL,NULL,role,admin - Email unique AND role=admin.
Inheritance

Constructors

UniqueRule([String? _table, String? _column, dynamic _ignoreId, String _ignoreColumn = 'id'])

Properties

customMessage String?
The error message to be returned if validation fails. Can be overridden by the user.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
signature String
Returns the unique signature of the rule. Defaults to the class name in snake_case (logic handled by registry usually, but good to have).
no setteroverride

Methods

message(ValidationContext context) String
Returns the validation error message.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
passes(ValidationContext context) FutureOr<bool>
Validates the value using the given context.
override
toString() String
A string representation of this object.
inherited

Operators

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