From 025dcd9054ddb5c1628fec470d5e80bd44025187 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 17 Jan 2023 09:24:36 +0100 Subject: [PATCH] chg: [alignment] Added validation rule to avoid duplicates --- src/Model/Table/AlignmentsTable.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Model/Table/AlignmentsTable.php b/src/Model/Table/AlignmentsTable.php index 3cbf5c5..975663a 100644 --- a/src/Model/Table/AlignmentsTable.php +++ b/src/Model/Table/AlignmentsTable.php @@ -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 {