When trying to update a model i am getting a EmptyResponse error
Bookshelf version: 1.2.0
Knex version: 0.21.4
When i want to save a model using:
await new Exam().where({ id: examId, professor_id: userId }).save(
{
attribute1: value1,
attribute2: value2
},
{ patch: true }
);
I'm getting a EmptyResponse error:
'CustomError: EmptyResponse
at Child.<anonymous> (/home/aurel/projects/omnescode/node_modules/bookshelf/lib/model.js:719:21)
at PassThroughHandlerContext.finallyHandler (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/finally.js:57:23)
at PassThroughHandlerContext.tryCatcher (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/promise.js…8)
at _drainQueueStep (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/home/aurel/projects/omnescode/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:439:21)'
While when doing it like this:
await Exam.forge({ id: examId, professor_id: userId }).save(
{
attribute1: value1,
attribute2: value2
},
{ patch: true }
);
I'm actually getting the model to be updated with the values that i give to it.
I read the docs and it said that if i pass a {require: false} the error should not show, however the problem still persists even though i am passing the require:false and the actual model that i want to update does exist in the database.
I think I know why this happens. In the first case the model instance created by new Exam() is empty, and when the model tries to refresh itself after saving there is no id to look for so you get the EmptyResponse error. Not sure how to solve this one, but it should be possible.
This should also work:
await new Exam({ id: examId }).where({ professor_id: userId }).save(
{
attribute1: value1,
attribute2: value2
},
{ patch: true }
)
Thanks for the quick reply!
Yes the method you proposed does work.
I do understand that this bug is not really something critical since there seem to be other working methods, but i thought giving the bookshelf team a heads up on this issue was a good idea.
I think forge has been depreciated.
Most helpful comment
Thanks for the quick reply!
Yes the method you proposed does work.
I do understand that this bug is not really something critical since there seem to be other working methods, but i thought giving the bookshelf team a heads up on this issue was a good idea.