/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/ProductFavoritesTable.php (2255B)
setTable('product_favorites');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
]);
$this->belongsTo('Products', [
'foreignKey' => 'product_id',
'joinType' => 'INNER',
]);
$this->hasMany('GalleryImages', [
'foreignKey' => 'foreign_key',
])->setConditions(['GalleryImages.model' => 'Products']);
$this->hasOne('FeaturedImage', [
'className' => 'GalleryImages',
'foreignKey' => 'foreign_key',
])->setConditions(['FeaturedImage.model' => 'Products', 'FeaturedImage.is_featured' => true]);
}
/**
* beforeSave. DON`T REMOVE
*/
function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->scalar('uuid')
->maxLength('uuid', 255)
->requirePresence('uuid', 'create')
->notEmptyString('uuid');
$validator
->boolean('is_active')
->notEmptyString('is_active');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
return $rules;
}
}