Skip to content

increment shows sql error after use scope query #10719

Closed

Description

@7insummer

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.

Activity

  1. added
    type: bug
    on Apr 8, 2019
  2. sushantdhiman commented on Apr 8, 2019

    @sushantdhiman
    Contributor

    Similar #10411 , #9572

  3. ALiangLiang commented on Apr 9, 2019

    @ALiangLiang
    Contributor

    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
  4. mhio commented on Nov 13, 2019

    @mhio

    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)
    
  5. added
    status: wip
    on Jan 15, 2020
  6. removed
    status: wip
    on Jan 21, 2020
  7. self-assigned this
    on Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions