bookshelf.js - bookshelf js save() command not updating rows in postgresql db -


js beginner trying postgresql db talking express.js through bookshelf.js.

github: https://github.com/duskyshelf/bookers-academy/blob/master/booker.js

var knex = require('knex')({   client: 'pg',   connection: "postgres://localhost/bookers" });  var bookshelf = require('bookshelf')(knex);  var user = bookshelf.model.extend({   tablename: 'users' });  var bob = new user({id: 2}); bob.save() 

bookshelf.js seems unable add content db.

current error message is: "unhandled rejection customerror: no rows updated'

when create model providing own id, in

var bob = new user({id: 2}); 

bookshelf assumes update operation, not insertion. sets internal isnew attribute false, , when save() invoked, instead of insert user(id, ...) values (2, ...);, executes update user ... id = 2;.

if there no user id = 2 update almost silently do nothing.

to force insert must change save() to:

bob.save(null, {method: 'insert'}); 

bookshelf save() documentation describes behavior.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -