TimestampBehavior::className(), 'updatedAtAttribute' => false, ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [ [ 'entity_id', 'parent_id', ], 'default', 'value' => null, ], [ [ 'entity_id', 'parent_id', ], 'integer', ], [ [ 'comment', 'entity' ], 'string', ], [ 'email', 'email', ], [ [ 'name', 'email', ], 'string', 'max' => 255, ], [ [ 'parent_id' ], 'exist', 'skipOnError' => true, 'targetClass' => Comment::className(), 'targetAttribute' => [ 'parent_id' => 'id' ], ], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => Yii::t('app', 'ID'), 'book_id' => Yii::t('app', 'Book ID'), 'name' => Yii::t('app', 'Name'), 'email' => Yii::t('app', 'Email'), 'comment' => Yii::t('app', 'Comment'), 'parent_id' => Yii::t('app', 'Parent ID'), ]; } /** * @return \yii\db\ActiveQuery */ public function getBook() { return $this->hasOne(Book::className(), [ 'id' => 'book_id' ]); } /** * @return \yii\db\ActiveQuery */ public function getParent() { return $this->hasOne(Comment::className(), [ 'id' => 'parent_id' ]); } /** * @return \yii\db\ActiveQuery */ public function getComments() { return $this->hasMany(Comment::className(), [ 'parent_id' => 'id' ]); } public function getActiveComments(){ return $this->getComments()->where(['status' => true]); } }