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
orOnCondition not set OR #6985
Comments
this is expected because onCondition is added to where using AND. What you try to do here is a relation using two different attributes with OR. This is not possible to declare properly because eager loading and JOIN does not work in this case. |
sorry to comment on a closed issue but i want to know why the eager loading fails to recognize the |
@fernandezekiel relation definition has to be generic and not bound to a specific record like it is done here by passing The relation is defined using the fields orOnCondition() in this case will add hope thats clear :) |
i have a slightly difference case, i'm not even passing public function getAuthRoles()
{
return $this->hasMany(AuthRole::className(), ['id' => 'auth_role_id'])->orOnCondition(['auth_role.title' => 'Authenticated'])->via('authRoleUsers');
} it produces the same kind of SQL as if i used |
this is normal because orOncondition will adjust the condition that is additinal to the condition that defines the relation. As you have not called onCondition before it, orOnCondition can not add anything. return $this->hasMany(AuthRole::className(), ['id' => 'auth_role_id'])->onCondition(['a' => 'b'])->orOnCondition(['auth_role.title' => 'Authenticated'])->via('authRoleUsers'); Would give you a query like JOIN ... ON id = auth_role_id AND (a= 'b' OR auth_role.title = 'Authenticated') |
+1 Same issue as @fernandezekiel There is no 'OR' option immediately after the initial where clause e.g. SELECT * FROM schema.tablename WHERE (0=1) AND "variable" = 'value' Note: orOnCondition produces ANDI want OR SELECT * FROM schema.tablename WHERE (0=1) OR "variable" = 'value' |
I have two tables. For example user and engage(have 2 related fields user1,user2).
When I try write relation:
public function getEngages() {
return $this->hasMany(Engage::className(), ['user1' => 'id'])->orOnCondition(['user2' => $this->id]);
}
it generates code:
SELECT * FROM
engage
WHERE (user1
=1) AND (user2
=1)",The text was updated successfully, but these errors were encountered: