yiisoft / yiisoft/active-record
joinWith and with using onCondition has problem with eager or lazy
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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