/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/CausesTable.php (3936B)
setTable('causes');
$this->setDisplayField('name');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER',
]);
// $this->hasMany('Orders', [
// 'foreignKey' => 'order_id',
// 'joinType' => 'INNER',
// ]);
$this->belongsToMany('CausesTags', [
'foreignKey' => 'cause_id',
'joinTable' => 'causes_tags',
]);
$this->belongsToMany('Tags', [
'foreignKey' => 'cause_id',
'targetForeignKey' => 'tag_id',
'joinTable' => 'causes_tags',
]);
$this->hasMany('CauseNews', [
'foreignKey' => 'cause_id',
'joinType' => 'INNER',
]);
$this->hasMany('GalleryImages', [
'foreignKey' => 'foreign_key',
])->setConditions(['GalleryImages.model' => 'Causes']);
$this->hasMany('BankAccounts', [
'foreignKey' => 'cause_id',
]);
$this->hasMany('Documents', [
'foreignKey' => 'foreign_key',
])->setConditions(['Documents.model' => 'Causes']);
$this->hasOne('FeaturedImage', [
'className' => 'GalleryImages',
'foreignKey' => 'foreign_key',
])->setConditions(
['FeaturedImage.model' => 'Causes', 'FeaturedImage.is_featured' => true]
);
}
/**
* 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->add(
'name',
[
'unique' => [
'rule' => 'validateUnique',
'provider' => 'table',
'message' => 'Acest titlu este utilizat. Va rugam folositi alt titlu'
]
]
);
$validator
->scalar('description')
->maxLength('description', 2000)
->requirePresence('description', 'create')
->notEmptyString('description');
$validator
->scalar('donation_amount')
->maxLength('donation_amount', 255)
->requirePresence('donation_amount', 'create')
->notEmptyString('donation_amount');
$validator
->date('date_start')
->notEmptyDate('date_start');
$validator
->date('date_end')
->notEmptyDate('date_end');
$validator
->boolean('is_active')
->requirePresence('is_active', 'create')
->notEmptyString('is_active');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*/
// public function buildRules(RulesChecker $rules): RulesChecker
// {
// $rules->add($rules->existsIn(['user_id'], 'Users'), ['errorField' => 'user_id']);
// $rules->add($rules->existsIn(['cause_image_id'], 'CauseImages'), ['errorField' => 'cause_image_id']);
// return $rules;
// }
}