Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (69 sloc) 2.43 KB
<?php
namespace App\Model\Table;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* Practises Model
*
* @property \App\Model\Table\UnitsTable|\Cake\ORM\Association\BelongsTo $Units
* @property \App\Model\Table\SpecialisationsTable|\Cake\ORM\Association\BelongsTo $Specialisations
*
* @method \App\Model\Entity\Practise get($primaryKey, $options = [])
* @method \App\Model\Entity\Practise newEntity($data = null, array $options = [])
* @method \App\Model\Entity\Practise[] newEntities(array $data, array $options = [])
* @method \App\Model\Entity\Practise|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method \App\Model\Entity\Practise patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \App\Model\Entity\Practise[] patchEntities($entities, array $data, array $options = [])
* @method \App\Model\Entity\Practise findOrCreate($search, callable $callback = null, $options = [])
*/
class PractisesTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('practises');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->belongsTo('Units', [
'foreignKey' => 'unit_id',
'joinType' => 'INNER'
]);
$this->belongsTo('Specialisations', [
'foreignKey' => 'specialisation_id',
'joinType' => 'INNER'
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmpty('id', 'create');
return $validator;
}
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['unit_id'], 'Units'));
$rules->add($rules->existsIn(['specialisation_id'], 'Specialisations'));
return $rules;
}
}