/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/CitiesTable.php (1909B)
setTable('cities');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->belongsTo('Counties', [
'foreignKey' => 'county_id',
'joinType' => 'INNER',
]);
$this->hasMany('UserAddresses', [
'foreignKey' => 'city_id',
]);
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->scalar('name')
->maxLength('name', 255)
->requirePresence('name', 'create')
->notEmptyString('name');
$validator
->scalar('county_name')
->maxLength('county_name', 255)
->requirePresence('county_name', 'create')
->notEmptyString('county_name');
$validator
->scalar('county_code')
->maxLength('county_code', 2)
->allowEmptyString('county_code');
$validator
->integer('extra_km')
->requirePresence('extra_km', 'create')
->notEmptyString('extra_km');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['county_id'], 'Counties'), ['errorField' => 'county_id']);
return $rules;
}
}