<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * WlSchooltypes Model
 *
 * @property \App\Model\Table\BudgetTable|\Cake\ORM\Association\HasMany $Budget
 *
 * @method \App\Model\Entity\WlSchooltype get($primaryKey, $options = [])
 * @method \App\Model\Entity\WlSchooltype newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\WlSchooltype[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\WlSchooltype|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\WlSchooltype patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\WlSchooltype[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\WlSchooltype findOrCreate($search, callable $callback = null, $options = [])
 *
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
class WlSchooltypesTable extends Table
{

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('wl_schooltypes');
        $this->setDisplayField('short');
        $this->setPrimaryKey('id');

        $this->addBehavior('Timestamp');

        $this->hasMany('Budget', [
            'foreignKey' => 'wl_schooltype_id'
        ]);
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->scalar('key_value')
            ->maxLength('key_value', 4)
            ->requirePresence('key_value', 'create')
            ->notEmpty('key_value');

        $validator
            ->scalar('short')
            ->maxLength('short', 10)
            ->requirePresence('short', 'create')
            ->notEmpty('short');

        $validator
            ->scalar('name')
            ->maxLength('name', 30)
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->dateTime('modfied')
            ->requirePresence('modfied', 'create')
            ->notEmpty('modfied');

        return $validator;
    }
}
