Class IsUnique

Checks that a list of fields from an entity are unique in the table

Namespace: Cake\ORM\Rule

Properties summary

  • $_fields protected
    string[]

    The list of fields to check

  • $_options protected
    array

    The options to use.

Method Summary

  • __construct() public

    Constructor.

  • __invoke() public

    Performs the uniqueness check

  • _alias() protected

    Add a model alias to all the keys in a set of conditions.

Method Detail

__construct() public

__construct(array $fields, array $options)

Constructor.

Options

  • allowMultipleNulls Set to false to disallow multiple null values in multi-column unique rules. By default this is true to emulate how SQL UNIQUE keys work.

Parameters

string[] $fields

The list of fields to check uniqueness for

array $options optional

The additional options for this rule.

__invoke() public

__invoke(\Cake\Datasource\EntityInterface $entity, array $options)

Performs the uniqueness check

Parameters

\Cake\Datasource\EntityInterface $entity

The entity from where to extract the fields where the repository key is required.

array $options

Options passed to the check,

Returns

bool

_alias() protected

_alias(mixed $alias, mixed $conditions, mixed $multipleNulls)

Add a model alias to all the keys in a set of conditions.

Null values will be omitted from the generated conditions, as SQL UNIQUE indexes treat NULL != NULL

Parameters

string $alias

The alias to add.

array $conditions

The conditions to alias.

bool $multipleNulls

Whether or not to allow multiple nulls.

Returns

array

Property Detail

$_fields protected

The list of fields to check

Type

string[]

$_options protected

The options to use.

Type

array

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.ORM.Rule.IsUnique.html