Class LinkConstraint
Checks whether links to a given association exist / do not exist.
Constants
Property Summary
-
$_association protected
Cake\ORM\Association|string
The association that should be checked.
-
$_requiredLinkState protected
string
The link status that is required to be present in order for the check to succeed.
Method Summary
-
__construct() public
Constructor.
-
__invoke() public
Callable handler.
-
_aliasFields() protected
Alias fields.
-
_buildConditions() protected
Build conditions.
-
_countLinks() protected
Count links.
Method Detail
__construct() ¶ public
__construct(Cake\ORM\Association|string $association, string $requiredLinkStatus)
Constructor.
Parameters
-
Cake\ORM\Association|string
$association The alias of the association that should be checked.
-
string
$requiredLinkStatus The link status that is required to be present in order for the check to succeed.
__invoke() ¶ public
__invoke(Cake\Datasource\EntityInterface $entity, array<string, mixed> $options): bool
Callable handler.
Performs the actual link check.
Parameters
-
Cake\Datasource\EntityInterface
$entity The entity involved in the operation.
-
array<string, mixed>
$options Options passed from the rules checker.
Returns
bool
_aliasFields() ¶ protected
_aliasFields(list<string> $fields, Cake\ORM\Table $source): list<string>
Alias fields.
Parameters
-
list<string>
$fields The fields that should be aliased.
-
Cake\ORM\Table
$source The object to use for aliasing.
Returns
list<string>
_buildConditions() ¶ protected
_buildConditions(list<string> $fields, array $values): array<string, string>
Build conditions.
Parameters
-
list<string>
$fields The condition fields.
-
array
$values The condition values.
Returns
array<string, string>
_countLinks() ¶ protected
_countLinks(Cake\ORM\Association $association, Cake\Datasource\EntityInterface $entity): int
Count links.
Parameters
-
Cake\ORM\Association
$association The association for which to count links.
-
Cake\Datasource\EntityInterface
$entity The entity involved in the operation.
Returns
int