TimestampBehavior::class, 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()'), ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [['created_at', 'updated_at'], 'safe'], [['title'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'title' => 'Название', 'created_at' => 'Дата создания', 'updated_at' => 'Дата изменения', ]; } public function beforeDelete() { foreach ($this->templateDocumentFields as $templateDocumentField){ $templateDocumentField->delete(); } return parent::beforeDelete(); } /** * @return \yii\db\ActiveQuery */ public function getDocuments() { return $this->hasMany(Document::className(), ['template_id' => 'id']); } /** * @return \yii\db\ActiveQuery */ public function getTemplateDocumentFields() { return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']); } }