newEntities(array $data, array $options = []) * @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) * @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = []) * @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = []) * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductPhoto|false save(EntityInterface $entity, array $options = []) * @method ProductPhoto 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 = []) * * @mixin TimestampBehavior */ class ProductPhotosTable 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('product_photos'); $this->setDisplayField('photo_filename'); $this->setPrimaryKey('id'); $this->setEntityClass( Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto') ); $this->addBehavior('Timestamp'); $this->belongsTo('Products', [ 'foreignKey' => 'product_id', 'joinType' => 'INNER', 'className' => 'CakeProducts.Products', ]); $this->belongsTo('ProductSkus', [ 'foreignKey' => 'product_sku_id', 'joinType' => 'LEFT', 'className' => 'CakeProducts.ProductSkus', ]); } /** * Default validation rules. * * @param Validator $validator Validator instance. * @return Validator */ public function validationDefault(Validator $validator): Validator { $validator ->uuid('product_id') ->notEmptyString('product_id'); $validator ->uuid('product_sku_id') ->allowEmptyString('product_sku_id'); $validator ->scalar('photo_dir') ->maxLength('photo_dir', 255) ->requirePresence('photo_dir', 'create') ->notEmptyString('photo_dir'); $validator ->scalar('photo_filename') ->maxLength('photo_filename', 255) ->requirePresence('photo_filename', 'create') ->notEmptyString('photo_filename'); $validator ->boolean('primary_photo') ->notEmptyString('primary_photo'); $validator ->integer('photo_position') ->notEmptyString('photo_position'); $validator ->boolean('enabled') ->notEmptyString('enabled'); $validator ->dateTime('deleted') ->allowEmptyDateTime('deleted'); 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->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); return $rules; } }