true, 'targetClass' => User::className(), 'targetAttribute' => ['from_user' => 'id']], [['to_user'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['to_user' => 'id']], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'chat_id' => 'Chat ID', 'status' => 'Status', 'comment' => 'Comment', 'from_user' => 'From User', 'to_user' => 'To User', ]; } /** * @return \yii\db\ActiveQuery */ public function getFromUser() { return $this->hasOne(User::className(), ['id' => 'from_user']); } /** * @return \yii\db\ActiveQuery */ public function getToUser() { return $this->hasOne(User::className(), ['id' => 'to_user']); } /** * @return \yii\db\ActiveQuery */ public function getMessages() { return $this->hasMany(Message::className(), ['chat_id' => 'chat_id'])->orderBy('message_id') ; } }