cockroachdb / cockroachdb/sequelize-cockroachdb

error updating an instance because of integer id treated as string

Ouverte
#11 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
55
Forks
18
Métriques de merge des PR
Aucune PR mergée en 30 j

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
})
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.