-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animal.php
81 lines (74 loc) · 2.15 KB
/
Animal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* This file is part of the mgrechanik/yii2-materialized-path library
*
* @copyright Copyright (c) Mikhail Grechanik <[email protected]>
* @license https://github.com/mgrechanik/yii2-materialized-path/blob/master/LICENCE.md
* @link https://github.com/mgrechanik/yii2-materialized-path
*/
namespace mgrechanik\yiimaterializedpath\tests\models;
use mgrechanik\yiimaterializedpath\MaterializedPathBehavior;
/**
* This is the model class for table "animal".
*
* The table with this model holds only one tree,
* in which all nodes (ar models) are connected hierarchically
*
* @property int $id
* @property string $path Path to parent node
* @property int $level Level of the node in the tree
* @property int $weight Weight among siblings
* @property string $name Name
*/
class Animal extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'animal';
}
public function behaviors()
{
return [
'materializedpath' => [
'class' => MaterializedPathBehavior::class,
'modelScenarioForChildrenNodesWhenTheyDeletedAfterParent' => 'SCENARIO_NOT_DEFAULT',
],
];
}
// Use this along with 'modelScenarioForChildrenNodesWhenTheyDeletedAfterParent' above
// to set up transaction for process when main node is deleted and all it's descendants
// need to move to their grandfather or to be deleted also
public function transactions()
{
return [
self::SCENARIO_DEFAULT => self::OP_DELETE,
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['level', 'weight'], 'integer'],
[['name'], 'required'],
[['path', 'name'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'path' => 'Path to parent node',
'level' => 'Level of the node in the tree',
'weight' => 'Weight among siblings',
'name' => 'Name',
];
}
}