remove product id from product category variants table
This commit is contained in:
parent
4549f30930
commit
892a85d30a
|
@ -28,10 +28,6 @@ class CreateProductCategoryVariants extends AbstractMigration
|
|||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('enabled', 'boolean', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
|
@ -42,18 +38,12 @@ class CreateProductCategoryVariants extends AbstractMigration
|
|||
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
|
||||
// $table->addIndex([
|
||||
// 'name',
|
||||
// 'product_category_id',
|
||||
// 'product_id',
|
||||
// ], [
|
||||
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
|
||||
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
|
||||
// 'unique' => true,
|
||||
// ]);
|
||||
$table->create();
|
||||
|
|
|
@ -12,11 +12,9 @@ use Cake\ORM\Entity;
|
|||
* @property string $id
|
||||
* @property string $name
|
||||
* @property string|null $product_category_id
|
||||
* @property string|null $product_id
|
||||
* @property bool $enabled
|
||||
*
|
||||
* @property ProductCategory|EntityInterface $product_category
|
||||
* @property Product|EntityInterface $product
|
||||
* @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options
|
||||
*/
|
||||
class ProductCategoryVariant extends Entity
|
||||
|
@ -33,12 +31,10 @@ class ProductCategoryVariant extends Entity
|
|||
protected array $_accessible = [
|
||||
'name' => true,
|
||||
'product_category_id' => true,
|
||||
'product_id' => true,
|
||||
'enabled' => true,
|
||||
|
||||
// entities
|
||||
'product_category' => false,
|
||||
'product' => false,
|
||||
'product_category_variant_options' => true,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -4,30 +4,37 @@ 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;
|
||||
use Cake\ORM\Query;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductCategoryVariant;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductCategoryVariants Model
|
||||
*
|
||||
* @property \App\Model\Table\ProductCategoriesTable&\Cake\ORM\Association\BelongsTo $ProductCategories
|
||||
* @property \App\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
||||
* @property ProductCategoriesTable&BelongsTo $ProductCategories
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
*
|
||||
* @method \App\Model\Entity\ProductCategoryVariant newEmptyEntity()
|
||||
* @method \App\Model\Entity\ProductCategoryVariant newEntity(array $data, array $options = [])
|
||||
* @method array<\App\Model\Entity\ProductCategoryVariant> newEntities(array $data, array $options = [])
|
||||
* @method \App\Model\Entity\ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method \App\Model\Entity\ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method \App\Model\Entity\ProductCategoryVariant patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<\App\Model\Entity\ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method \App\Model\Entity\ProductCategoryVariant|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method \App\Model\Entity\ProductCategoryVariant saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<\App\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\App\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<\App\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\App\Model\Entity\ProductCategoryVariant>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method ProductCategoryVariant newEmptyEntity()
|
||||
* @method ProductCategoryVariant newEntity(array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariant> newEntities(array $data, array $options = [])
|
||||
* @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductCategoryVariant> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductCategoryVariant>|ResultSetInterface<ProductCategoryVariant> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ProductCategoryVariantsTable extends Table
|
||||
{
|
||||
|
@ -54,11 +61,6 @@ class ProductCategoryVariantsTable extends Table
|
|||
'bindingKey' => 'internal_id',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'className' => 'CakeProducts.Products',
|
||||
]);
|
||||
|
||||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
|
@ -70,8 +72,8 @@ class ProductCategoryVariantsTable extends Table
|
|||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
|
@ -101,14 +103,13 @@ class ProductCategoryVariantsTable extends Table
|
|||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
// $rules->add($rules->isUnique(['name', 'product_category_id', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ class ProductCategoryVariantsTable extends Table
|
|||
* @param SelectQuery $query
|
||||
* @param string $internalCategoryId
|
||||
*
|
||||
* @return array|\Cake\ORM\Query|SelectQuery
|
||||
* @return array|Query|SelectQuery
|
||||
*/
|
||||
public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue