cockroachdb / cockroachdb/sequelize-cockroachdb

error updating an instance because of integer id treated as string

Open
#11 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
55
Forks
18
PR merge metrics
No merged PRs in 30d

Description

When I do an update from its instance
```
User.findOne({ where: { email: "my@email.com" } }).then(user => {
user.update({ password })
})
```
It triggers an error saying
```
SequelizeDatabaseError: unsupported comparison operator: =
```
Because it tries to do this query
```
UPDATE "user" SET "name"='My name',"reset_at"='2017-07-28 07:04:52.688 +00:00',"updated_at"='2017-07-28 07:04:52.706 +00:00' WHERE "id" = '265875070405378049'
```
Notice quotes between id `'265875070405378049'` where it should be an integer instead of string. I have the same error when I am trying to update the association such as
```
user.getProfile().then(profile => {
profile.update({ name })
})
```
The closest workaround I found is from this [comment](https://github.com/sequelize/sequelize/issues/2383#issuecomment-58006083) by setting `require('pg').defaults.parseInt8 = true`. I do get an integer id when doing the above query, but the weird thing is I do not get the right id.

For example if my id in db is `265875070405378049` the query produces something like `... WHERE "id" = 265875070405378050`. Most of the time it uses an integer +/- 1 of the actual id. Same thing going on when I create a record with association. the `User.id` will be something like `265923186502860801` but the `user_id` in `Profile` will be like `265923186502860800`

For the record my model is as simple as
```
const User = sequelize.define('user', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
}, {
underscored: true,
constraints: false,
timestamps: true
})
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.