Bookshelf.js : Avoid fetch call after call to save (update)

Viewed 201

We are using bookshelf.js with MySQL.

We have a Table: Contact(id, name, email_Id, updated_Contact_At)

bookshelf Query :

new Contact({id: 1}).save(
    {name: 'Jhon Snow', email_Id: 'jhonsnow42@gmail.com', birthdate:'1998-10-21'},
    {patch: true, default: false, require: true, method: 'update'}
);

which translates to :

Update Contact set name = "Jhon Snow", 
email_Id = 'jhonsnow1212@gmail.com', 
birthdate = '1998-10-21', 
updated_Contact_At = 020-06-08T09:18:10.513Z 
where id = 1;

after executing above query bookshelf fetches the same record:

select Contact.* from Contact where Contact.id = 1 limit 1

Is there any way in bookshelf.js to stop fetch call after updating record?

1 Answers

You can use autoRefresh = false while updating record

new Contact({id: 1}).save(
    {name: 'Jhon Snow', email_Id: 'jhonsnow42@gmail.com', birthdate:'1998-10-21'},
    {patch: true, default: false, require: true, method: 'update', autoRefresh : false}
);

use Bookshelf.js version: ^1.2.0

Related