bookshelf icon indicating copy to clipboard operation
bookshelf copied to clipboard

Refresh Fails after update (EmptyResponse- NotFoundError)

Open ronaksv opened this issue 5 years ago • 0 comments

Introduction

Update fails when 'autoRefresh' true, but succeeds when false. Below code was working in 0.14.2, but not in 1.2.0

Issue Description

I have a query where I need to update a number of rows based on a condition using 'in' clause. This is what I have written

data = {is_approved: 1, updated_at: new Date()};
User.where('id', 'in', reqData.user_ids)
    .where('role_id',reqData.role_id)
    .save(
            data,
            { method: 'update', require: true, transacting: t, debug: true }
        )
    .then((data) => {
        wCb(null, data);
    })
    .catch((err) => {
        return reject(err);
    });
Screenshot 2020-11-11 at 11 30 47

The above query expands properly and updates the database (when autoRefresh=false) , but when it executes refresh and tries to fetch the updated record, it fails with below error

Screenshot 2020-11-11 at 11 31 11

The above statement fails and gives error of "EmptyResponse"

The reason is when it tries to do "_doFetch" after update, it does not find any record.
The below code/ss is from node_modules/bookshelf/lib/model.js

Screenshot 2020-11-11 at 11 24 29

Expected behaviour

It should autorefresh properly using all the attributes. (This was working in 0.14.2, but not in 1.2.0)

ronaksv avatar Nov 11 '20 06:11 ronaksv