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

increment shows sql error after use scope query #10719

Closed
7insummer opened this issue Apr 8, 2019 · 3 comments · Fixed by #11852
Closed

increment shows sql error after use scope query #10719

7insummer opened this issue Apr 8, 2019 · 3 comments · Fixed by #11852
Assignees

Comments

@7insummer
Copy link

What are you doing?

I just want increment field of a model instance after scope query.
see codes below:

Movie.scope('bh').findOne({where:{id:1}}).then(movie=>{
movie.increment('fav_nums',{by:1})
})

bh is name of a scope,defined by code below:

  scopes: {
            bh: {
                attributes: { exclude: ['created_at', 'updated_at','deleted_at'] }
            }
        }

What do you expect to happen?

when query ,i need this scope to exclude some attributes,after query,i just want increment a field of model instance 。but see the sql below,wrong sql generated。

What is actually happening?

very simple code ,but will cause sql errors。because the code above will be translated into sqls like this:

UPDATE movie SET fav_nums=fav_nums+ 1,exclude='created_at', 'updated_at', 'deleted_at',updated_at='2019-01-21 15:59:18' WHERE id = 1

Obviously,the sql is wrong。

Dialect: mysql
__Dialect version:
__Database version:5.6
__Sequelize version: 5.2.12
__Tested with latest release:yes,5.2.12

Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.

@sushantdhiman
Copy link
Contributor

Similar #10411 , #9572

ALiangLiang added a commit to ALiangLiang/sequelize that referenced this issue Apr 9, 2019
@ALiangLiang
Copy link
Contributor

ALiangLiang commented Apr 9, 2019

reproduce: ALiangLiang@be03653

UPDATE `Users` SET `aNumber`=`aNumber`+ 1,`exclude`='age', 'created_at', 'updated_at',
`updatedAt`='1970-01-01 00:00:00' WHERE `id` = 1

@mhio
Copy link

mhio commented Nov 13, 2019

Same problem in sqlite

  defaultScope: {
    attributes: { exclude: ['no'] },
  },
Executing (default): UPDATE `fives` SET `count`=`count`+ 1,`exclude`='no',`updated_at`='2019-11-13 02:04:09.956 +00:00' WHERE `id` = '63cb2731-0dd7-4c1e-9aef-b6f65201301f'
(node:75249) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: SQLITE_ERROR: no such column: exclude
    at Query.formatError (/project/node_modules/sequelize/lib/dialects/sqlite/query.js:422:16)
    at Query._handleQueryResponse (/project/node_modules/sequelize/lib/dialects/sqlite/query.js:73:18)
    at afterExecute (/project/node_modules/sequelize/lib/dialects/sqlite/query.js:250:31)
    at Statement.errBack (/project/node_modules/sqlite3/lib/sqlite3.js:16:21)

@papb papb added the status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. label Jan 15, 2020
@papb papb removed the status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. label Jan 21, 2020
@papb papb self-assigned this Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants