Repository navigation
Open
Labels
existing workaroundFor issues. There is a known workaround for this issue.
Description
[✔] I have read the contribution guidelines
Bug Description
I'm trying to use [Op.or] to execute a query
User.findOne({
where: { email: payload.email.trim(), '$accesses.isAccess$': 1 },
include: [{
model: Access,
as: 'accesses',
on: {
[Op.or]: [{'$User.web_roles_id$': Sequelize.col('accesses.web_roles_id')}, {'$User.id$': Sequelize.col('accesses.web_users_id')}]
},
include: [{
model: Route,
as: 'routes'
}]
}]
});
, but it doesn't work correctly, for some reason it throws out the fields '$User.web_roles_id$' and '$User.id$' that I want to use in comparison.
What do you expect to happen?
That should run the following query:
SELECT ... FROM [web_users] AS [User]
LEFT OUTER JOIN [web_access] AS [accesses] ON[User].[web_roles_id] = [accesses].[web_roles_id] or [User].[id] = [accesses].[web_users_id]
LEFT OUTER JOIN [web_route] AS [accesses->routes] ON [accesses].[web_route_id] = [accesses->routes].[id]
WHERE [User].[email] = N'[email protected]' AND [accesses].[isAccess] = 1;
What is actually happening?
It is running this instead: (fields '$User.web_roles_id$' and '$User.id$' not in operation)
SELECT ... FROM [web_users] AS [User]
LEFT OUTER JOIN [web_access] AS [accesses] ON ([accesses].[web_roles_id] OR [accesses].[web_users_id])
LEFT OUTER JOIN [web_route] AS [accesses->routes] ON [accesses].[web_route_id] = [accesses->routes].[id]
WHERE [User].[email] = N'[email protected]' AND [accesses].[isAccess] = 1;
Additional context
My associations:
User.hasMany(Access, { foreignKey: "roleId", sourceKey: "roleId", as: "accesses" });
Access.belongsTo(User, { foreignKey: "roleId", targetKey: "roleId", as: "user" });
Access.hasMany(Route, { foreignKey: "id", sourceKey: "routeId", as: "routes" });
Route.belongsTo(Access, { foreignKey: "id", targetKey: "routeId", as: "accesses" });
Environment
- Sequelize version: 6.13.0
- Node.js version: 16.4.2
- If TypeScript related: TypeScript version: 4.5.4
Bug Report Checklist
How does this problem relate to dialects?
- [✔] I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- [✔] Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Metadata
Metadata
Assignees
Labels
existing workaroundFor issues. There is a known workaround for this issue.
Type
Projects
- StatusShow more project fieldsNo status
Activity
WikiRik commentedon Feb 16, 2022
Thanks for the bug report! It looks like this is something that should work. Can you make an SSCCE or failing test(s) in a PR for this issue so we can look into this?
eugenestepaniuk commentedon Feb 17, 2022
@WikiRik
sequelize/sequelize-sscce@main...eugenestepanyuk:patch-1
eugenestepaniuk commentedon Feb 23, 2022
@WikiRik
please tell me when i will get an answer to my problem or how can i know the solution?
ephys commentedon Feb 23, 2022
The problem isn't fixed yet but I found a workaround that works: use
where()instead of the POJO syntax.Something like this:
I hope #14020 will fix the underlying issue
WikiRik commentedon Feb 23, 2022
Thanks for looking into this @ephys
Since there is a workaround that's not too much work I think it's best to just leave this for now and fix it with #14020 for the v7 release.
@eugenestepanyuk please confirm if the workaround did actually fix this issue for you
eugenestepaniuk commentedon Feb 23, 2022
yes, thx, this workaround works
now i found one more workaround
I will hope that you will be able to solve the problem without auxiliary properties
[-]Incorrect operation of the Op.or[/-][+]Column references are broken when used in `IncludeOptions.on`[/+]