Class ExistsIn
Checks that the value provided in a field exists as the primary key of another table.
Namespace: Cake\ORM\Rule
Property Summary
-
$_fields protected
array
The list of fields to check
-
$_repository protected
array
The repository where the field will be looked for
Method Summary
-
__construct() public
Constructor.
-
__invoke() public
Performs the existence check
-
_fieldsAreNull() protected
Check whether or not the entity fields are nullable and null.
Method Detail
__construct() ¶ public
__construct(string|array $fields, object|string $repository)
Constructor.
Parameters
-
string|array
$fields The field or fields to check existence as primary key.
-
object|string
$repository The repository where the field will be looked for, or the association name for the repository.
__invoke() ¶ public
__invoke(Cake\Datasource\EntityInterface $entity, array $options): bool
Performs the existence check
Parameters
-
Cake\Datasource\EntityInterface
$entity The entity from where to extract the fields
-
array
$options Options passed to the check, where the
repository
key is required.
Returns
bool
Throws
RuntimeException
When the rule refers to an undefined association.
_fieldsAreNull() ¶ protected
_fieldsAreNull(Cake\Datasource\EntityInterface $entity, Cake\ORM\Table $source): bool
Check whether or not the entity fields are nullable and null.
Parameters
-
Cake\Datasource\EntityInterface
$entity The entity to check.
-
Cake\ORM\Table
$source The table to use schema from.
Returns
bool