2025-04-05 02:06:23 -07:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace CakeProducts\Model\Table;
|
|
|
|
|
|
|
|
|
|
use Cake\Core\Configure;
|
|
|
|
|
use Cake\ORM\RulesChecker;
|
|
|
|
|
use Cake\ORM\Table;
|
|
|
|
|
use Cake\Validation\Validator;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ProductAttributes Model
|
|
|
|
|
*
|
|
|
|
|
* @property \App\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products
|
|
|
|
|
* @property \App\Model\Table\ProductCategoryAttributesTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributes
|
|
|
|
|
* @property \App\Model\Table\ProductCategoryAttributeOptionsTable&\Cake\ORM\Association\BelongsTo $ProductCategoryAttributeOptions
|
|
|
|
|
*
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute newEmptyEntity()
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute newEntity(array $data, array $options = [])
|
|
|
|
|
* @method array<\App\Model\Entity\ProductAttribute> newEntities(array $data, array $options = [])
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute 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\ProductAttribute findOrCreate($search, ?callable $callback = null, array $options = [])
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
|
|
|
|
|
* @method array<\App\Model\Entity\ProductAttribute> patchEntities(iterable $entities, array $data, array $options = [])
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
|
|
|
|
* @method \App\Model\Entity\ProductAttribute saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
|
|
|
|
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false saveMany(iterable $entities, array $options = [])
|
|
|
|
|
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> saveManyOrFail(iterable $entities, array $options = [])
|
|
|
|
|
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = [])
|
|
|
|
|
* @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = [])
|
|
|
|
|
*/
|
|
|
|
|
class ProductAttributesTable extends Table
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Initialize method
|
|
|
|
|
*
|
|
|
|
|
* @param array<string, mixed> $config The configuration for the Table.
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function initialize(array $config): void
|
|
|
|
|
{
|
|
|
|
|
parent::initialize($config);
|
|
|
|
|
|
|
|
|
|
$this->setTable('product_attributes');
|
|
|
|
|
$this->setDisplayField('id');
|
|
|
|
|
$this->setPrimaryKey('id');
|
|
|
|
|
|
|
|
|
|
$this->setEntityClass(
|
|
|
|
|
Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->belongsTo('Products', [
|
|
|
|
|
'foreignKey' => 'product_id',
|
|
|
|
|
'className' => 'CakeProducts.Products',
|
|
|
|
|
'joinType' => 'INNER',
|
|
|
|
|
]);
|
|
|
|
|
$this->belongsTo('ProductCategoryAttributes', [
|
|
|
|
|
'foreignKey' => 'product_category_attribute_id',
|
|
|
|
|
'className' => 'CakeProducts.ProductCategoryAttributes',
|
|
|
|
|
'joinType' => 'INNER',
|
|
|
|
|
]);
|
|
|
|
|
$this->belongsTo('ProductCategoryAttributeOptions', [
|
|
|
|
|
'foreignKey' => 'product_category_attribute_option_id',
|
|
|
|
|
'className' => 'CakeProducts.ProductCategoryAttributeOptions',
|
|
|
|
|
]);
|
2025-04-08 01:30:40 -07:00
|
|
|
|
2025-04-05 02:06:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default validation rules.
|
|
|
|
|
*
|
|
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance.
|
|
|
|
|
* @return \Cake\Validation\Validator
|
|
|
|
|
*/
|
|
|
|
|
public function validationDefault(Validator $validator): Validator
|
|
|
|
|
{
|
|
|
|
|
$validator
|
|
|
|
|
->uuid('product_id')
|
|
|
|
|
->notEmptyString('product_id');
|
|
|
|
|
|
|
|
|
|
$validator
|
|
|
|
|
->uuid('product_category_attribute_id')
|
|
|
|
|
->notEmptyString('product_category_attribute_id');
|
|
|
|
|
|
|
|
|
|
$validator
|
|
|
|
|
->scalar('attribute_value')
|
|
|
|
|
->maxLength('attribute_value', 255)
|
|
|
|
|
->allowEmptyString('attribute_value');
|
|
|
|
|
|
|
|
|
|
$validator
|
|
|
|
|
->uuid('product_category_attribute_option_id')
|
|
|
|
|
->allowEmptyString('product_category_attribute_option_id');
|
|
|
|
|
|
2025-04-08 01:30:40 -07:00
|
|
|
$validator
|
|
|
|
|
->dateTime('deleted')
|
|
|
|
|
->allowEmptyDateTime('deleted');
|
|
|
|
|
|
2025-04-05 02:06:23 -07:00
|
|
|
return $validator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
public function buildRules(RulesChecker $rules): RulesChecker
|
|
|
|
|
{
|
|
|
|
|
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
|
|
|
|
$rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']);
|
|
|
|
|
$rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']);
|
|
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
}
|
|
|
|
|
}
|