D
D
Daaeev2021-09-22 22:24:33
Yii
Daaeev, 2021-09-22 22:24:33

What's wrong with the request?

Help me please!! I've been sitting on this for an hour now. I have no idea what to do.
Saw a chela on Stack OverFlow with the same problem, but they did not help him ((
Here is the code

$questions = Question::find()
            ->joinWith('questionToTagTags')
            ->where(['questionToTagTags.tag_id' => $tag_id, 'status' => 1])
            ->andWhere(['!=', 'id', $question_id])
            ->with('comments', 'userToQuestionSubs')
            ->limit(10)
            ->all();

SQLSTATE[ 42S22
] outputs: Column not found: 1054 Unknown column 'questionToTagTags.tag_id' in 'where clause'
The SQL being executed was: SELECT `question`.* FROM `question` LEFT JOIN `question_to_tag_tags` ON ​​`question` .`id` = `question_to_tag_tags`.`question_id` WHERE ((`questionToTagTags`.`tag_id`=34) AND (`

status` =1)) AND (`id` != 15) LIMIT 10 that a column was not found, etc., but with tables everything is fine with me. There are similar queries, for example this one works fine:
$questions_query = Question::find()
            ->joinWith('comments')
            ->where(['status' => 1, 'comments.question_id' => null])
            ->with('questionToTagTags.tag', 'userToQuestionSubs')
            ->orderBy('id DESC');

Here is the link

public function getQuestionToTagTags()
    {
        return $this->hasMany(QuestionToTagTags::class, ['question_id' => 'id']);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2021-09-22
@Daaeev

In the where clause, write the table name correctly.
question_to_tag_tags instead of the questionToTagTags association name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question