-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
It is impossible to create relation with "not equal" condition. OnCondition not supports conditions for columns #153
Comments
If we fix you problem - in populate be cyclical relation For your problem - simple add $query = new ActiveQuery(Document::class, $db);
$query->alias('documents')->joinWith('duplicates')
->andWhere(new Expression('{{dup}}.{{id}} != {{documents}}.{{id}}'))
->all(); And i recommend use for quote |
Unfortunately, a result of populated models with this query is not correct and contains duplicated ids in $model->duplicates ; |
You can also use |
Required query
Try to define a relation in model Document
Query
Fails with error
But command SQL is OK :
return
SELECT "documents".* FROM "documents" "documents" LEFT JOIN "documents" "dup" ON ("documents"."filehash" = "dup"."filehash" AND "documents"."company_id" = "dup"."company_id") AND ("dup"."id" != "documents"."id")
The problem comes from ActiveQuery populate
https://github.com/yiisoft/db/blob/master/src/Query/Query.php#L203
https://github.com/yiisoft/active-record/blob/master/src/ActiveQuery.php#L250
active-record/src/ActiveQueryTrait.php
Line 161 in 02b5ea1
This method replaces values from relation "link" to real values, but it doesn't touch "onCondition" expression,
active-record/src/ActiveRelationTrait.php
Line 548 in 02b5ea1
This method executes wrong query
active-record/src/ActiveRelationTrait.php
Line 304 in 02b5ea1
The text was updated successfully, but these errors were encountered: