我们将 bookshelf.js 与 MySQL 结合使用。
我们有一个表:联系人(id, name, email_Id, Updated_Contact_At
)
书架查询:
new Contact({id: 1}).save(
{name: 'Jhon Snow', email_Id: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cda7a5a2a3bea3a2baf9ff8daaa0aca4a1e3aea2a0" rel="noreferrer noopener nofollow">[email protected]</a>', birthdate:'1998-10-21'},
{patch: true, default: false, require: true, method: 'update'}
);
翻译为:
Update Contact set name = "Jhon Snow",
email_Id = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18727077766b76776f292a292a587f75797174367b7775" rel="noreferrer noopener nofollow">[email protected]</a>',
birthdate = '1998-10-21',
updated_Contact_At = 020-06-08T09:18:10.513Z
where id = 1;
执行上述查询后,bookshelf 会获取相同的记录:
select Contact.* from Contact where Contact.id = 1 limit 1
bookshelf.js 中有什么方法可以在更新记录后停止 fetch 调用吗?
最佳答案
更新记录时可以使用 autoRefresh = false
new Contact({id: 1}).save(
{name: 'Jhon Snow', email_Id: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8be1e3e4e5f8e5e4fcbfb9cbece6eae2e7a5e8e4e6" rel="noreferrer noopener nofollow">[email protected]</a>', birthdate:'1998-10-21'},
{patch: true, default: false, require: true, method: 'update', autoRefresh : false}
);
使用 Bookshelf.js 版本:^1.2.0
关于javascript - 书架.js : Avoid fetch call after call to save (update),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62261020/