Completed
Push — master ( 41af6a...be871c )
by Fèvre
11s
created

PollsTable::validationDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
namespace App\Model\Table;
3
4
use Cake\ORM\Table;
5
use Cake\Validation\Validator;
6
7
class PollsTable extends Table
8
{
9
10
    /**
11
     * Initialize method
12
     *
13
     * @param array $config The configuration for the Table.
14
     *
15
     * @return void
16
     */
17
    public function initialize(array $config)
18
    {
19
        parent::initialize($config);
20
21
        $this->table('polls');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::table() has been deprecated with message: 3.4.0 Use setTable()/getTable() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
        $this->displayField('name');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::displayField() has been deprecated with message: 3.4.0 Use setDisplayField()/getDisplayField() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
23
        $this->primaryKey('id');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Table::primaryKey() has been deprecated with message: 3.4.0 Use setPrimaryKey()/getPrimaryKey() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
24
25
        $this->addBehavior('Timestamp');
26
27
        $this->belongsTo('Users', [
28
            'foreignKey' => 'user_id'
29
        ]);
30
        $this->belongsTo('BlogArticles', [
31
            'foreignKey' => 'article_id'
32
        ]);
33
        $this->hasMany('PollsAnswers', [
34
            'foreignKey' => 'poll_id',
35
            'dependent' => true,
36
            'cascadeCallbacks' => true
37
        ]);
38
        $this->hasMany('PollsUsers', [
39
            'foreignKey' => 'poll_id',
40
            'dependent' => true,
41
            'cascadeCallbacks' => true
42
        ]);
43
    }
44
45
    /**
46
     * Default validation rules.
47
     *
48
     * @param \Cake\Validation\Validator $validator Validator instance.
49
     *
50
     * @return \Cake\Validation\Validator
51
     */
52
    public function validationDefault(Validator $validator)
53
    {
54
        $validator
55
            ->requirePresence('name', 'create')
56
            ->notEmpty('name');
57
58
        return $validator;
59
    }
60
}
61