1 | <?php |
||
28 | abstract class BaseEntityModel extends ActiveRecord |
||
29 | { |
||
30 | use EntityTrait; |
||
31 | |||
32 | /** |
||
33 | * Initialize new entity. |
||
34 | */ |
||
35 | 60 | public function init() |
|
36 | { |
||
37 | 60 | if ($this->skipInit) { |
|
38 | return; |
||
39 | } |
||
40 | 60 | $this->initEntityEvents(); |
|
41 | 60 | $this->checkAttributes(); |
|
42 | 60 | parent::init(); |
|
43 | 60 | } |
|
44 | |||
45 | /** |
||
46 | * Check whether all properties meet the standards. If you want to disable |
||
47 | * checking, please override this method and return true directly. This |
||
48 | * method runs when environment is not production or disable debug mode. |
||
49 | * @return boolean true if all checks pass. |
||
50 | * @throws NotSupportedException |
||
51 | */ |
||
52 | 60 | public function checkAttributes() |
|
53 | { |
||
54 | 60 | if (YII_ENV !== YII_ENV_PROD || YII_DEBUG) { |
|
55 | 60 | if (!is_string($this->idAttribute) && empty($this->idAttribute) && |
|
56 | 60 | !is_string($this->guidAttribute) && empty($this->guidAttribute)) { |
|
57 | $errorInfo = 'ID and GUID attributes are not be disabled simultaneously in relational database.'; |
||
58 | throw new \yii\base\NotSupportedException($errorInfo); |
||
59 | } |
||
60 | 60 | } |
|
61 | 60 | return true; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | * ------------ |
||
67 | * This static method will take $queryClass property to query class. If it is |
||
68 | * not a string, The [[BaseEntityQuery]] will be taken. |
||
69 | * This static method will build non-init model first, so you wouldn't build it any more. |
||
70 | * @return BaseEntityQuery the newly created [[BaseEntityQuery]] |
||
71 | * or its extended class instance. |
||
72 | */ |
||
73 | 60 | public static function find() |
|
82 | } |
||
83 |