unique rules, allow product id to be null in product photos
CI / testsuite (mysql, 8.2, ) (push) Waiting to run Details
CI / testsuite (mysql, 8.4, ) (push) Waiting to run Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Waiting to run Details
CI / Coding Standard & Static Analysis (push) Waiting to run Details

This commit is contained in:
Brandon Shipley 2025-11-01 23:16:59 -07:00
parent 2041fc78d3
commit d239a98e8e
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
4 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class AllowProductIdToBeNullInProductPhotos extends BaseMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_photos');
$table->changeColumn('product_id', 'uuid', [
'default' => null,
'limit' => 11,
'null' => true,
]);
$table->update();
}
}

View File

@ -10,7 +10,7 @@ use Cake\ORM\Entity;
* ProductPhoto Entity * ProductPhoto Entity
* *
* @property string $id * @property string $id
* @property string $product_id * @property string|null $product_id
* @property string|null $product_category_id * @property string|null $product_category_id
* @property string|null $product_sku_id * @property string|null $product_sku_id
* @property string $photo_dir * @property string $photo_dir
@ -55,6 +55,8 @@ class ProductPhoto extends Entity
'deleted' => true, 'deleted' => true,
// entities // entities
'product' => true, 'product' => false,
'product_sku' => false,
'product_category' => false,
]; ];
} }

View File

@ -108,6 +108,7 @@ class ProductCategoryAttributeOptionsTable extends Table
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker
{ {
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
$rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id']));
return $rules; return $rules;
} }

View File

@ -105,6 +105,7 @@ class ProductCategoryVariantOptionsTable extends Table
public function buildRules(RulesChecker $rules): RulesChecker public function buildRules(RulesChecker $rules): RulesChecker
{ {
$rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']);
$rules->add($rules->isUnique(['variant_value', 'product_category_variant_id']));
return $rules; return $rules;
} }