php - Argument 2 passed to yiidbconditionsHashConditionBuilder::build() must be of the type array, string given in Yii2
Get the solution ↓↓↓when i trying to make join between two tables i get error.
here is my controller
public function actionView($id)
{
$view = (new \yii\db\Query())
->select(['id', 'user_id', 'body', 'title'])
->join('INNER JOIN', 'users', 'blog.user_id','users.id')
->where(['blog.id' => $id])
->one();
return $this->render('view', compact('view'));
}
here is my view
<div class="col-lg-4">
<h2><?= $view['name'] . ' ' . $view['surname'] ?></h2>
<h3><?= $view['title']; ?></h3>
<p><?= $view['body']; ?></p>
<a href="<?php echo yii::$app->homeUrl; ?>" class="btn btn-default">Back </a>
<?= Html::a('Delete', ['delete', 'id' => $view['id']], ['class' => 'btn btn-danger']) ?>
</div>
Answer
Solution:
On prima vista, it's obvious that you had forgot thefrom
clause of theQueryBuilder
.
Take a look into this:
$view = (new \yii\db\Query())
->select(['id', 'user_id', 'body', 'title'])
->from('blog') // this is your from clause of the query
->join('INNER JOIN', 'users', 'blog.user_id = users.id')
->where(['blog.id' => $id])
->one();
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: sqlstate[23000]: integrity constraint violation: 1452 cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.