-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Here's an example: https://api.cakephp.org/5.0/class-Cake.ORM.Table.html#exists()
Checks uniqueness of a given value in a given column
A case to handle would be a Users table rule checking username uniqueness before signing up.
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['username']), ['errorField' => 'username']);
}
The built-in CakePHP validator needs to be able to check whether username was taken across the whole table, without scoping search to a specific account. Therefore, TenantScopeBehavior needs to recognise and ignore such queries.
Here's the current source code for Cake\ORM\Table::exists().
public function exists(QueryExpression|Closure|array|string|null $conditions): bool
{
return (bool)count(
$this->find('all')
->select(['existing' => 1])
->where($conditions)
->limit(1)
->disableHydration()
->toArray()
);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels