You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to chain "withScope" on a model, when using a raw SQL where clause it doesn't merge the successive scopes with "and". This kind of thing used to work in Sequelize 6 via whereMergeStrategy, but seems broken in Sequelize 7.0.0-alpha.40
Reproducible Example
import{Op,WhereOptions,sql,ModelStatic}from"@sequelize/core"import{User}from"@/models"constterms=["aaa","bbb","ccc"]letuserScope: ModelStatic<User>=Userfor(consttermofterms){consttermPattern=`%${term}%`constwhere=sql`LOWER(first_name) like ${termPattern} OR LOWER(last_name) like ${termPattern} OR LOWER(display_name) like ${termPattern}`userScope=userScope.withScope({ where })}constuserResults3=awaituserScope.findAll({logging: console.log,})
which produces the SQL
SELECT
[id],
...
[deleted_at] AS [deletedAt]
FROM
[users] AS [User]
WHERE
[User].[deleted_at] IS NULLAND (
LOWER(first_name) like N'%ccc%'ORLOWER(last_name) like N'%ccc%'ORLOWER(display_name) like N'%ccc%'
);
What do you expect to happen?
I would expect it to do this
import{Op,WhereOptions,sql,ModelStatic}from"@sequelize/core"import{User}from"@/models"constterms=["aaa","bbb","ccc"]constuserWhere: {[Op.and]?: WhereOptions<User>[]}={}constuserWhereConditions: WhereOptions<User>[]=terms.map((term: string)=>{consttermPattern=`%${term}%`returnsql`LOWER(first_name) like ${termPattern} OR LOWER(last_name) like ${termPattern} OR LOWER(display_name) like ${termPattern}`})userWhere[Op.and]=userWhereConditionsconstuserResults2=awaitUser.findAll({where: userWhere,logging: console.log})
which produces the SQL
SELECT
[id],
...
[deleted_at] AS [deletedAt]
FROM
[users] AS [User]
WHERE
[User].[deleted_at] IS NULLAND (
(
LOWER(first_name) like N'%aaa%'ORLOWER(last_name) like N'%aaa%'ORLOWER(display_name) like N'%aaa%'
)
AND (
LOWER(first_name) like N'%bbb%'ORLOWER(last_name) like N'%bbb%'ORLOWER(display_name) like N'%bbb%'
)
AND (
LOWER(first_name) like N'%ccc%'ORLOWER(last_name) like N'%ccc%'ORLOWER(display_name) like N'%ccc%'
)
);
What is actually happening?
As far as I can tell its just replacing the query instead of merging it.
No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered:
Issue Creation Checklist
Bug Description
When I try to chain "withScope" on a model, when using a raw SQL where clause it doesn't merge the successive scopes with "and". This kind of thing used to work in Sequelize 6 via
whereMergeStrategy
, but seems broken in Sequelize7.0.0-alpha.40
Reproducible Example
which produces the SQL
What do you expect to happen?
I would expect it to do this
which produces the SQL
What is actually happening?
As far as I can tell its just replacing the query instead of merging it.
Environment
Would you be willing to resolve this issue by submitting a Pull Request?
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
The text was updated successfully, but these errors were encountered: