Test Setup Failed
Push — master ( 1d5188...8ee063 )
by giu
09:14
created

OrganizationsTable::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
namespace App\Model\Table;
3
4
use Cake\ORM\Query;
5
use Cake\ORM\RulesChecker;
6
use Cake\ORM\Table;
7
use Cake\Validation\Validator;
8
9
/**
10
 * Organizations Model
11
 *
12
 * @property \App\Model\Table\UsersTable|\Cake\ORM\Association\BelongsTo $Users
13
 *
14
 * @method \App\Model\Entity\Organization get($primaryKey, $options = [])
15
 * @method \App\Model\Entity\Organization newEntity($data = null, array $options = [])
16
 * @method \App\Model\Entity\Organization[] newEntities(array $data, array $options = [])
17
 * @method \App\Model\Entity\Organization|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
18
 * @method \App\Model\Entity\Organization patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
19
 * @method \App\Model\Entity\Organization[] patchEntities($entities, array $data, array $options = [])
20
 * @method \App\Model\Entity\Organization findOrCreate($search, callable $callback = null, $options = [])
21
 *
22
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
23
 */
24
class OrganizationsTable extends Table
25
{
26
27
    /**
28
     * Initialize method
29
     *
30
     * @param array $config The configuration for the Table.
31
     * @return void
32
     */
33
    public function initialize(array $config)
34
    {
35
        parent::initialize($config);
36
37
        $this->setTable('organizations');
38
        $this->setDisplayField('name');
39
        $this->setPrimaryKey('id');
40
41
        $this->addBehavior('Timestamp');
42
43
        $this->belongsTo('Users', [
44
            'foreignKey' => 'user_id',
45
            'joinType' => 'INNER'
46
        ]);
47
    }
48
49
    /**
50
     * Default validation rules.
51
     *
52
     * @param \Cake\Validation\Validator $validator Validator instance.
53
     * @return \Cake\Validation\Validator
54
     */
55
    public function validationDefault(Validator $validator)
56
    {
57
        $validator
58
            ->integer('id')
59
            ->allowEmpty('id', 'create');
60
61
        $validator
62
            ->scalar('name')
63
            ->maxLength('name', 255)
64
            ->requirePresence('name', 'create')
65
            ->notEmpty('name');
66
67
        return $validator;
68
    }
69
70
    /**
71
     * Returns a rules checker object that will be used for validating
72
     * application integrity.
73
     *
74
     * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
75
     * @return \Cake\ORM\RulesChecker
76
     */
77
    public function buildRules(RulesChecker $rules)
78
    {
79
        $rules->add($rules->existsIn(['user_id'], 'Users'));
80
81
        return $rules;
82
    }
83
}
84