Hello. I am adding friends.
Here is the table:
By default, status = 0. As the user confirmed the second, then 1. user_id is the one who first added. fried_id someone added. Tell me how I can now correctly select data from the table, namely: friends of a particular user.
public function actionIndex($id){ $user = User::findOne($id); if(empty($user)){ throw new \yii\web\HttpException(404, 'Такого пользователя нет!'); } $list_friend = Friend::find()->where(['status' => 1]) ->andWhere(['friend_id' => $id]) ->andWhere(['user_id' => $id]) ->limit(5) ->orderBy('RAND()')->all(); // так не правильно... } user_id - submitted a friend request. The friend_id is the one who wanted to add. From the table it is clear that the user with id 3 has added a user with id 1. etc.
