MCPcopy
hub / github.com/sequelize/sequelize / _paranoidClause

Method _paranoidClause

lib/model.js:176–218  ·  view source on GitHub ↗
(model, options = {})

Source from the content-addressed store, hash-verified

174
175 // validateIncludedElements should have been called before this method
176 static _paranoidClause(model, options = {}) {
177 // Apply on each include
178 // This should be handled before handling where conditions because of logic with returns
179 // otherwise this code will never run on includes of a already conditionable where
180 if (options.include) {
181 for (const include of options.include) {
182 this._paranoidClause(include.model, include);
183 }
184 }
185
186 // apply paranoid when groupedLimit is used
187 if (_.get(options, 'groupedLimit.on.options.paranoid')) {
188 const throughModel = _.get(options, 'groupedLimit.on.through.model');
189 if (throughModel) {
190 options.groupedLimit.through = this._paranoidClause(throughModel, options.groupedLimit.through);
191 }
192 }
193
194 if (!model.options.timestamps || !model.options.paranoid || options.paranoid === false) {
195 // This model is not paranoid, nothing to do here;
196 return options;
197 }
198
199 const deletedAtCol = model._timestampAttributes.deletedAt;
200 const deletedAtAttribute = model.rawAttributes[deletedAtCol];
201 const deletedAtObject = {};
202
203 let deletedAtDefaultValue = Object.prototype.hasOwnProperty.call(deletedAtAttribute, 'defaultValue') ? deletedAtAttribute.defaultValue : null;
204
205 deletedAtDefaultValue = deletedAtDefaultValue || {
206 [Op.eq]: null
207 };
208
209 deletedAtObject[deletedAtAttribute.field || deletedAtCol] = deletedAtDefaultValue;
210
211 if (Utils.isWhereEmpty(options.where)) {
212 options.where = deletedAtObject;
213 } else {
214 options.where = { [Op.and]: [deletedAtObject, options.where] };
215 }
216
217 return options;
218 }
219
220 static _addDefaultAttributes() {
221 const tail = {};

Callers 3

findAllMethod · 0.95
aggregateMethod · 0.95
updateMethod · 0.95

Calls 1

getMethod · 0.65

Tested by

no test coverage detected