chg: [alignment] Added validation rule to avoid duplicates

develop-unstable
Sami Mokaddem 2023-01-17 09:24:36 +01:00
parent 697c068ca6
commit 025dcd9054
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 11 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\ORM\RulesChecker;
use Cake\Validation\Validator;
class AlignmentsTable extends AppTable
@ -24,7 +25,16 @@ class AlignmentsTable extends AppTable
->notEmptyString('organisation_id')
->requirePresence(['individual_id', 'organisation_id'], 'create');
return $validator;
}
}
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(
['individual_id', 'organisation_id', 'type'],
__('This alignment already exists.')
));
return $rules;
}
public function setAlignment($organisation_id, $individual_id, $type): void
{