BlogArticlesLikesTable::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 10
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 BlogArticlesLikesTable 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
        $this->table('blog_articles_likes');
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...
20
        $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...
21
22
        $this->addBehavior('Timestamp');
23
        $this->addBehavior('CounterCache', [
24
            'BlogArticles' => ['like_count']
25
        ]);
26
27
        $this->belongsTo('BlogArticles', [
28
            'foreignKey' => 'article_id',
29
        ]);
30
        $this->belongsTo('Users', [
31
            'foreignKey' => 'user_id',
32
        ]);
33
    }
34
35
    /**
36
     * Default validation rules.
37
     *
38
     * @param \Cake\Validation\Validator $validator Instance of the validator.
39
     *
40
     * @return \Cake\Validation\Validator
41
     */
42
    public function validationDefault(Validator $validator)
43
    {
44
        $validator
45
            ->notEmpty('article_id')
46
            ->add('article_id', 'numeric', [
47
                'rule' => 'numeric'
48
            ])
49
            ->notEmpty('user_id')
50
            ->add('user_id', 'numeric', [
51
                'rule' => 'numeric'
52
            ]);
53
54
        return $validator;
55
    }
56
}
57