static get softDeleteColumn() { if (_.isString(this.softDelete)) { return this.softDelete; } return 'deletedAt'; }
delete() { if (!this.modelClass().softDelete) { return super.delete(); } return this.softDelete(); }
/** * Delete pet * * @override * @param {API.DeletePetRequest} req deletePet request * @param {API.Context<State>} [ctx] koa context */ async deletePet(req, ctx) { const { pet } = ctx.state; await pet.softDelete(); }
// define which columns will be converted to Date object when parsing this model static set timestampColumns(columns) { if (this.timestamps) { if (this.timestamps === true) { columns.push('createdAt'); columns.push('updatedAt'); } else { if (this.timestamps.createdAt) { columns.push(this.timestamps.createdAt); } if (this.timestamps.updatedAt) { columns.push(this.timestamps.updatedAt); } } } if (this.softDelete) { columns.push(this.softDeleteColumn); } this.__timestampColumns = _.uniq(columns); }
trash() { return this.softDelete(); }
static get systemColumns() { if (!this._systemColumns) { const columns = []; // timestamps (createdAt + updatedAt handling) if (this.timestamps) { if (this.timestamps === true) { columns.push('createdAt'); columns.push('updatedAt'); } else { if (this.timestamps.createdAt) { columns.push(this.timestamps.createdAt); } if (this.timestamps.updatedAt) { columns.push(this.timestamps.updatedAt); } } } if (this.softDelete) { columns.push(this.softDeleteColumn); } this._systemColumns = columns; } return this._systemColumns; }
!this.schema.softDelete && isUploadable && this._entry[key] && if (this.schema.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', }); }); }
/** * Delete pet * * @override * @param {API.DeletePetRequest} req deletePet request * @param {API.Context<State>} [ctx] koa context */ async deletePet(req, ctx) { const { pet } = ctx.state; await pet.softDelete(); }