Skip to content

Postgres JSONB 'destroy' with 'where' object fails #5092

@ahadinyoto

Description

@ahadinyoto

I'm using sequelize 3.15.0, postgres dialect on Mac OS X (El Cap). I have a column with JSONB
type. When destroying by using where object, it throws an exception.

var Page = sequelize.define('Page', {
  content: Sequelize.JSONB
})
Page.create({ name: "Test", content: { title: "Title" } })
.then(() => {
  Page.destroy({ where: { content: { title: "Title" } } })
  .then(() => {
    sequelize.close()
  })
})

It throws.

Unhandled rejection TypeError: val.replace is not a function
    at Object.SqlString.escape (/tmp/myapp/node_modules/sequelize/lib/sql-string.js:56:15)
    at Object.QueryGenerator.escape (/tmp/myapp/node_modules/sequelize/lib/dialects/abstract/query-generator.js:983:22)
    ...

When using netsted key content.title, it also throws an exception though a different one.

Page.destroy({ where: { 'content.title': "Title" } })
Unhandled rejection SequelizeDatabaseError: column "content.title" does not exist
    at Query.formatError (/tmp/myapp/node_modules/sequelize/lib/dialects/postgres/query.js:347:14)
    at null.<anonymous> (/tmp/myapp/node_modules/sequelize/lib/dialects/postgres/query.js:81:19)
    ...

However, using that same 'where' object with findOne or findAll works perfectly as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions