Answer the question
In order to leave comments, you need to log in
Why does Yii2 throw an error Primary key of 'common\models\PostCategory' can not be empty when fetching?
I make a linked selection
$query = PostCategory::find()->joinWith('category')
->where([
'post_id' => $id,
'category_id' => $category_id,
])
->andWhere([
'category_id.user_id' => Yii::$app->user->getId()
]);
$post = $query->one();
SELECT `post_category`.* FROM `post_category` LEFT JOIN `category` ON `post_category`.`category_id` = `category`.`id` WHERE ((`post_id`='58') AND (`category_id`='4')) AND (`category`.`user_id`=1)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question