yiisoft / yiisoft/active-record

joinWith and with using onCondition has problem with eager or lazy

Open
#44 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:to be verified type:bug
Dominant language
PHP
Stars
119
Forks
38
Avg merge
1h 11m
Merged PRs (30d)
1

Description

What steps will reproduce the problem?

I want select all failures with related job only if it has a reason on failure table and I use this

$failures = Failure::find()
        ->joinWith([
            'job' => function ($query) {
                $query->andOnCondition(['failure.reason' => 1]);
            }
])->all();
Error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'failure.reason' in 'where clause'
SELECT * FROM job WHERE (job_id=2) AND (failure.reason=1)

Additional info

I have used (with) and (joinWith) also used (true and false) as second param to indicate eager or lazy and always get same error

Q A
Yii version 2.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Failure::find()->joinWith() example and compare it with with(), using both eager and lazy loading. Trace how joinWith, with, and andOnCondition build the generated SQL, especially the query shown for job. Done means the reported condition is handled consistently without the unknown-column error, with behavior verified for the documented loading modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.