Reputation: 451
I'm using this code in one of my server boot script-
var server = require('../server');
var ds = server.dataSources.mysql;
var express = require('express');
var request = require('request');
var router = express.Router();
module.exports = function(app) {
app.get('/test',function(req,res){
//console.log(server.model);
server.models.Company.update({
filter: {
where: {
id: 1
},
},
},
name: 's12'
});
});
};
the problem is it updates all row in the database. How should I make this function so that it updates name where id is 1.
please help me into this.
Upvotes: 1
Views: 1572
Reputation: 2610
Jerome WAGNER is right when he says there isn't an update
method - it's updateAll
. Furthermore you shouldn't use the full filter syntax for non query methods, and you need to include a callback method. From the docs:
When you call the Node APIs for methods other than queries, don't wrap the where clause in a
{ where : ... }
object...
So your example should be:
app.get('/test',function(req,res){
//console.log(server.model);
server.models.Company.updateAll({ id: 1 }, { name: 's12' }, function(err, info) {
...
});
});
Upvotes: 4