uuids instead of int ids fore xternal product catalogs, test fixes, many to many working now

This commit is contained in:
2025-03-31 01:30:09 -07:00
parent 4c65d23e2b
commit 025017537f
11 changed files with 43 additions and 31 deletions

View File

@@ -56,11 +56,13 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
$this->addBehavior('Timestamp');
$this->belongsTo('ExternalProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogs',
// 'foreignKey' => 'external_product_catalog_id',
'joinType' => 'INNER',
]);
$this->belongsTo('ProductCatalogs', [
'foreignKey' => 'product_catalog_id',
'className' => 'CakeProducts.ProductCatalogs',
// 'foreignKey' => 'product_catalog_id',
'joinType' => 'INNER',
]);
}
@@ -74,8 +76,7 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('external_product_catalog_id')
->maxLength('external_product_catalog_id', 255)
->uuid('external_product_catalog_id')
->notEmptyString('external_product_catalog_id');
$validator
@@ -99,8 +100,8 @@ class ExternalProductCatalogsProductCatalogsTable extends Table
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
// $rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']);
// $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
return $rules;
}

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
@@ -54,12 +55,17 @@ class ExternalProductCatalogsTable extends Table
$this->addBehavior('Timestamp');
$this->setEntityClass(
Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog')
);
$this->belongsToMany('ProductCatalogs', [
'through' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ProductCatalogs',
]);
$this->hasMany('ExternalProductCatalogsProductCatalogs', [
'foreignKey' => 'external_product_catalog_id',
'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
]);
}
@@ -72,10 +78,6 @@ class ExternalProductCatalogsTable extends Table
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->uuid('product_catalog_id')
->notEmptyString('product_catalog_id');
$validator
->scalar('base_url')
->maxLength('base_url', 255)
@@ -106,8 +108,6 @@ class ExternalProductCatalogsTable extends Table
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']);
return $rules;
}
}

View File

@@ -54,7 +54,7 @@ class ProductCatalogsTable extends Table
'className' => 'CakeProducts.ProductCategories',
]);
$this->belongsToMany('ExternalProductCatalogs', [
'through' => 'CakeProducts.ExternalProductCatalogsProductCatalogs',
'through' => 'ExternalProductCatalogsProductCatalogs',
'className' => 'CakeProducts.ExternalProductCatalogs',
]);
}