newEntities(array $data, array $options = []) * @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method Product findOrCreate($search, ?callable $callback = null, array $options = []) * @method Product patchEntity(EntityInterface $entity, array $data, array $options = []) * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method Product|false save(EntityInterface $entity, array $options = []) * @method Product saveOrFail(EntityInterface $entity, array $options = []) * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ class ProductsTable extends Table { /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ public function initialize(array $config): void { parent::initialize($config); $this->setTable('products'); $this->setDisplayField('name'); $this->setPrimaryKey('id'); $this->belongsTo('ProductCategories', [ 'foreignKey' => 'product_category_id', 'bindingKey' => 'internal_id', 'joinType' => 'INNER', 'className' => 'CakeProducts.ProductCategories', ]); $this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class)); } /** * Default validation rules. * * @param Validator $validator Validator instance. * @return Validator */ public function validationDefault(Validator $validator): Validator { $validator ->scalar('name') ->maxLength('name', 255) ->requirePresence('name', 'create') ->notEmptyString('name'); $validator ->uuid('product_category_id') ->notEmptyString('product_category_id'); $validator ->integer('product_type_id') ->requirePresence('product_type_id', 'create') ->notEmptyString('product_type_id'); return $validator; } /** * Returns a rules checker object that will be used for validating * application integrity. * * @param RulesChecker $rules The rules object to be modified. * @return RulesChecker */ public function buildRules(RulesChecker $rules): RulesChecker { $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => '0']); $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => '1']); return $rules; } }