FormulesTable.php 1.28 KB
<?php
namespace App\Model\Table;

use App\Model\Entity\Formule;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Formules Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Fichemetrologique
 * @property \Cake\ORM\Association\HasMany $Variables
 */
class FormulesTable extends AppTable
{

    /**
     * Initialize method
     *
     * @param array $config
     *            The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);
        
        $this->setTable('formules');
        $this->setDisplayField('id');
        $this->setPrimaryKey('id');
        
        $this->belongsTo('Fichemetrologiques', [
            'foreignKey' => 'formule_id'
        ]);
        $this->hasMany('Variables', [
            'foreignKey' => 'formule_id',
            'dependent' => true
        ]);
    }

    /**
     * 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');
        
        return $validator;
    }
}