【问题标题】:Bookshelf.js : Avoid fetch call after call to save (update)Bookshelf.js:避免调用保存(更新)后的获取调用
【发布时间】:2020-06-08 11:27:35
【问题描述】:

我们在 MySQL 中使用 bookshelf.js。

我们有一张桌子:联系方式(id, name, email_Id, updated_Contact_At)

书架查询:

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'}
);

翻译成:

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;

执行上述查询书架后获取相同的记录:

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

bookshelf.js 中是否有任何方法可以在更新记录后停止 fetch 调用?

【问题讨论】:

    标签: javascript bookshelf.js


    【解决方案1】:

    更新记录时可以使用 autoRefresh = false

    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}
    );
    

    使用 Bookshelf.js 版本:^1.2.0

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 1970-01-01
      • 2020-11-13
      • 2011-01-22
      • 2011-08-26
      • 1970-01-01
      • 2020-10-19
      • 2011-01-24
      • 2018-07-22
      相关资源
      最近更新 更多