Back
validatesUniquenessOf()
Name | Type | Required | Default | Description |
---|---|---|---|---|
properties | string | No |
Name of property or list of property names to validate against (can also be called with the property argument).
|
|
message | string | No | [property] has already been taken | Supply a custom error message here to override the built-in one. |
when | string | No | onSave |
Pass in onCreate or onUpdate to limit when this validation occurs (by default validation will occur on both create and update, i.e. onSave ).
|
allowBlank | boolean | No | false |
If set to true , validation will be skipped if the property value is an empty string or doesn't exist at all. This is useful if you only want to run this validation after it passes the validatesPresenceOf test, thus avoiding duplicate error messages if it doesn't.
|
scope | string | No | One or more properties by which to limit the scope of the uniqueness constraint. | |
condition | string | No |
String expression to be evaluated that decides if validation will be run (if the expression returns true validation will run).
|
|
unless | string | No |
String expression to be evaluated that decides if validation will be run (if the expression returns false validation will run).
|
|
includeSoftDeletes | boolean | No | true |
Set to true to include soft-deleted records in the queries that this method runs.
|
// Make sure that two users with the same username won't ever exist in the database table validatesUniquenessOf(property="username", message="Sorry, that username is already taken."); // Same as above but allow identical usernames as long as they belong to a different account validatesUniquenessOf(property="username", scope="accountId");
Copied!