webadmin/AdminMappingsTable.php

75 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2017-06-22 12:48:15 +00:00
<?php
namespace App\Model\Table;
use App\Model\Entity\AdminMapping;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
* AdminMappings Model
*
* @property \Cake\ORM\Association\BelongsTo $Users
* @property \Cake\ORM\Association\BelongsTo $AccountMappings
*/
class AdminMappingsTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->table('admin_mappings');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
$this->belongsTo('AccountMappings', [
'foreignKey' => 'account_mapping_id',
'joinType' => 'INNER'
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
*/
public function validationDefault(Validator $validator)
{
$validator
->uuid('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)
{
$rules->add($rules->existsIn(['user_id'], 'Users'));
$rules->add($rules->existsIn(['account_mapping_id'], 'AccountMappings'));
$rules->add($rules->isUnique(['account_mapping_id', 'user_id']), ['message' => 'unique error']);
return $rules;
}
}