Skip to content

Commit

Permalink
add unique on faqquestions - question #59
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickakk committed Nov 9, 2024
1 parent b3973ca commit b0ed471
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Changes
- Added unique validation for invite translation - language id #59
- Added unique validation for faq questions - question #59


## Version 2024-11
Expand Down
22 changes: 22 additions & 0 deletions config/Migrations/202411091410_AddQuestionIndexToFaqQuestions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Migrations\AbstractMigration;

class AddQuestionIndexToFaqQuestions extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('faq_questions');
$table->addIndex('question', ['unique' => true]);
$table->update();
}
}
2 changes: 1 addition & 1 deletion src/Model/Table/FaqQuestionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function validationDefault(Validator $validator): Validator
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['faq_category_id'], 'FaqCategories'), ['errorField' => 'faq_category_id']);

$rules->add($rules->isUnique(['question']), ['errorField' => 'question']);
return $rules;
}
}

0 comments on commit b0ed471

Please sign in to comment.