Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joinWith and with using onCondition has problem with eager or lazy #44

Open
gholizadeh opened this issue Mar 30, 2019 · 4 comments
Open
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@gholizadeh
Copy link

gholizadeh commented Mar 30, 2019

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
@gholizadeh
Copy link
Author

also I found svit-ws commented on a same issue 2 years ago.

@rob006
Copy link
Contributor

rob006 commented Mar 30, 2019

Is there any reason why you're not using:

$failures = Failure::find()
        ->andWhere(['failure.reason' => 1])
        ->joinWith(['job'])
        ->all();

?

@gholizadeh
Copy link
Author

@rob006 because as I said I want all failures and the job (but I need the job only if failure has reason). it will gives the failures have reason not all failures

@gholizadeh
Copy link
Author

It would be grate if andOnCondition and OnCondition had another param that indicate the scope of condition (in join as a general condition or in joined table which is considered by default and really useful in most of the times)

@samdark samdark added type:bug Bug status:to be verified Needs to be reproduced and validated. labels Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants