cockroachdb / cockroachdb/sequelize-cockroachdb
error updating an instance because of integer id treated as string
- Ngôn ngữ chính
- JavaScript
- Star
- 55
- Fork
- 18
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
})
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.