delete() { if (!this.modelClass().softDelete) { return super.delete(); } return this.softDelete(); }
_handleSoftDelete() { const model = this.modelClass(); if (!model.softDelete) return; this.onBuildKnex((knex, builder) => { if ( // don't add soft delete condition to partial queries (inside functions) builder._isPartialQuery || !builder.isFind() || builder.context().withTrashed ) return; const softDeleteColumn = `${model.tableName}.${model.softDeleteColumn}`; // add the deletedAt statement if (builder.context().onlyTrashed) { knex.where(q => q.whereNotNull(softDeleteColumn)); } else { knex.where(q => q.whereNull(softDeleteColumn)); } // push the _ww statement which wraps up the upcoming where condition in brackets // this is done in knex_patch.js knex._statements.push({ grouping: 'where', type: '_ww', }); }); }