-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Description
Codes
// Product model definition
this.Product = this.sequelize.define('product', {
id: {
type: Sequelize.INTEGER(11).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false
},
pid: {
type: Sequelize.STRING,
unique: true,
allowNull: false
},
ean: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
alias: {
type: Sequelize.STRING,
unique: true
},
name: {
type: Sequelize.STRING,
allowNull: false
},
cost: {
type: Sequelize.DECIMAL(18, 9),
allowNull: false
},
price: {
type: Sequelize.DECIMAL(18, 9),
allowNull: false
}
})
// upsert code (I'm using expressjs):
Product.upsert({
id: 1,
name: 'Test Product 100',
pid: 'test-pid-113',
ean: 'test-ean-43',
alias: 'test-alias-23',
cost: 1.5,
price: 3
})
.then((ins) => {
res.send({
OK: true,
updated: ins
})
})
.catch((err) => {
res.send({
OK: false,
err: err
})
})Results
Originally, I had:
{
"id": 1,
"pid": "test-pid-113",
"ean": "test-ean-43",
"alias": "test-alias-23",
"name": "Test Product 5",
"cost": 1.5,
"price": 3,
"createdAt": "2017-01-08T10:17:54.000Z",
"updatedAt": "2017-01-09T04:11:44.000Z"
}After update, I had:
{
"id": 1,
"pid": "test-pid-113",
"ean": "test-ean-43",
"alias": "test-alias-23",
"name": "Test Product 100",
"cost": 1.5,
"price": 3,
"createdAt": "2017-01-08T10:17:54.000Z",
"updatedAt": "2017-01-09T04:11:44.000Z"
}Looked good, but the return value from the .then promise was false. That is, when I went to the http endpoint, I got this result:
{ OK: true, updated: false }
Placed a break-point at the promise function and inspected the return value. Got the same result.
What I expect is:
{ OK: true, updated: true }
Thanks for reading all these. Any help will be greatly appreciated.
Dialect: mysql
Database version: 5.7.11
Sequelize version: 3.29.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels