【问题标题】:How to hard delete by bookshelf when soft delete enable启用软删除时如何通过书架硬删除
【发布时间】:2020-08-24 22:48:45
【问题描述】:

假设,我想暂时删除,以便可以使用书架软删除,但在这种情况下,当我需要永久删除表格的行时。那么,当为模型启用软删除时,我该怎么做呢?

`use strict`

const Bookshelf = require('../bookshelf');

module.exports = Bookshelf.model('contactUs', {
    tableName: `contact_us`,
    hasTimestamps: ['created_at', 'updated_at'],
    softDelete: true,
    hidden: ['deleted_at'],

    parse: function (response) {
        if (response.allowUseOfMyContactInformation != null) {
            response.allowUseOfMyContactInformation = !!+response.allowUseOfMyContactInformation
        }
        return response;

    }
})

【问题讨论】:

    标签: mysql sql node.js knex.js bookshelf.js


    【解决方案1】:

    如果您想永久删除某些内容,即使模型启用了软删除,请将 hardDelete 设置为 true 例如

    new contactUs({ id }).destroy({ hardDelete: true })
    

    【讨论】:

      猜你喜欢
      • 2011-12-26
      • 1970-01-01
      • 2019-08-07
      • 2013-10-08
      • 1970-01-01
      • 2018-03-30
      • 2016-09-13
      • 2020-05-27
      • 2012-05-13
      相关资源
      最近更新 更多