Skip to content

Commit a8842a4

Browse files
committed
build: v1.2.1
1 parent 14b501e commit a8842a4

File tree

4 files changed

+97
-16
lines changed

4 files changed

+97
-16
lines changed

dist/vuex-orm-soft-delete.common.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,19 @@ function Query(context, query) {
193193
* false = include soft deletes
194194
* null = exclude soft deletes
195195
*/
196-
query.prototype.softDeletesFilter = null;
196+
query.prototype.softDeleteSelectFilter = null;
197197
/**
198198
* Constraint includes soft deleted models.
199199
*/
200200
query.prototype.withTrashed = function () {
201-
this.softDeletesFilter = false;
201+
this.softDeleteSelectFilter = false;
202202
return this;
203203
};
204204
/**
205205
* Constraint restricts to only soft deleted models.
206206
*/
207207
query.prototype.onlyTrashed = function () {
208-
this.softDeletesFilter = true;
208+
this.softDeleteSelectFilter = true;
209209
return this;
210210
};
211211
/**
@@ -260,6 +260,33 @@ function Query(context, query) {
260260
.onlyTrashed()
261261
.get();
262262
};
263+
/**
264+
* Patch any new queries so that sub queries, such as relation queries,
265+
* can respect top level modifiers. For many-to-many relations, due to core
266+
* API limitations, we're forced to pass-through intermediate models.
267+
*/
268+
var newQuery = query.prototype.newQuery;
269+
query.prototype.newQuery = function (entity) {
270+
var patchedQuery = newQuery.call(this, entity);
271+
// Only patch queries that are loading relations.
272+
var loadables = Object.keys(this.load);
273+
if (loadables.length > 0) {
274+
patchedQuery.softDeleteSelectFilter = this.softDeleteSelectFilter;
275+
if (entity && entity !== this.entity && this.model.hasPivotFields()) {
276+
var fields = this.model.pivotFields().reduce(function (fields, field) {
277+
Object.keys(field).filter(function (entity) { return loadables.includes(entity); }).forEach(function (entity) {
278+
fields.push(field[entity].pivot.entity);
279+
});
280+
return fields;
281+
}, []);
282+
// Release an entity that is an intermediate to a loadable relation.
283+
if (fields.includes(entity)) {
284+
patchedQuery.softDeleteSelectFilter = false;
285+
}
286+
}
287+
}
288+
return patchedQuery;
289+
};
263290
/**
264291
* Fetch all soft deletes from the store and group by entity.
265292
*/
@@ -280,11 +307,11 @@ function Query(context, query) {
280307
var _this = this;
281308
return models.filter(function (model) {
282309
// Only soft deletes
283-
if (_this.softDeletesFilter === true) {
310+
if (_this.softDeleteSelectFilter === true) {
284311
return model.$trashed();
285312
}
286313
// Include soft deletes
287-
if (_this.softDeletesFilter === false) {
314+
if (_this.softDeleteSelectFilter === false) {
288315
return models;
289316
}
290317
// Exclude soft deletes

dist/vuex-orm-soft-delete.esm.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ function Query(context, query) {
191191
* false = include soft deletes
192192
* null = exclude soft deletes
193193
*/
194-
query.prototype.softDeletesFilter = null;
194+
query.prototype.softDeleteSelectFilter = null;
195195
/**
196196
* Constraint includes soft deleted models.
197197
*/
198198
query.prototype.withTrashed = function () {
199-
this.softDeletesFilter = false;
199+
this.softDeleteSelectFilter = false;
200200
return this;
201201
};
202202
/**
203203
* Constraint restricts to only soft deleted models.
204204
*/
205205
query.prototype.onlyTrashed = function () {
206-
this.softDeletesFilter = true;
206+
this.softDeleteSelectFilter = true;
207207
return this;
208208
};
209209
/**
@@ -258,6 +258,33 @@ function Query(context, query) {
258258
.onlyTrashed()
259259
.get();
260260
};
261+
/**
262+
* Patch any new queries so that sub queries, such as relation queries,
263+
* can respect top level modifiers. For many-to-many relations, due to core
264+
* API limitations, we're forced to pass-through intermediate models.
265+
*/
266+
var newQuery = query.prototype.newQuery;
267+
query.prototype.newQuery = function (entity) {
268+
var patchedQuery = newQuery.call(this, entity);
269+
// Only patch queries that are loading relations.
270+
var loadables = Object.keys(this.load);
271+
if (loadables.length > 0) {
272+
patchedQuery.softDeleteSelectFilter = this.softDeleteSelectFilter;
273+
if (entity && entity !== this.entity && this.model.hasPivotFields()) {
274+
var fields = this.model.pivotFields().reduce(function (fields, field) {
275+
Object.keys(field).filter(function (entity) { return loadables.includes(entity); }).forEach(function (entity) {
276+
fields.push(field[entity].pivot.entity);
277+
});
278+
return fields;
279+
}, []);
280+
// Release an entity that is an intermediate to a loadable relation.
281+
if (fields.includes(entity)) {
282+
patchedQuery.softDeleteSelectFilter = false;
283+
}
284+
}
285+
}
286+
return patchedQuery;
287+
};
261288
/**
262289
* Fetch all soft deletes from the store and group by entity.
263290
*/
@@ -278,11 +305,11 @@ function Query(context, query) {
278305
var _this = this;
279306
return models.filter(function (model) {
280307
// Only soft deletes
281-
if (_this.softDeletesFilter === true) {
308+
if (_this.softDeleteSelectFilter === true) {
282309
return model.$trashed();
283310
}
284311
// Include soft deletes
285-
if (_this.softDeletesFilter === false) {
312+
if (_this.softDeleteSelectFilter === false) {
286313
return models;
287314
}
288315
// Exclude soft deletes

dist/vuex-orm-soft-delete.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,19 @@
197197
* false = include soft deletes
198198
* null = exclude soft deletes
199199
*/
200-
query.prototype.softDeletesFilter = null;
200+
query.prototype.softDeleteSelectFilter = null;
201201
/**
202202
* Constraint includes soft deleted models.
203203
*/
204204
query.prototype.withTrashed = function () {
205-
this.softDeletesFilter = false;
205+
this.softDeleteSelectFilter = false;
206206
return this;
207207
};
208208
/**
209209
* Constraint restricts to only soft deleted models.
210210
*/
211211
query.prototype.onlyTrashed = function () {
212-
this.softDeletesFilter = true;
212+
this.softDeleteSelectFilter = true;
213213
return this;
214214
};
215215
/**
@@ -264,6 +264,33 @@
264264
.onlyTrashed()
265265
.get();
266266
};
267+
/**
268+
* Patch any new queries so that sub queries, such as relation queries,
269+
* can respect top level modifiers. For many-to-many relations, due to core
270+
* API limitations, we're forced to pass-through intermediate models.
271+
*/
272+
var newQuery = query.prototype.newQuery;
273+
query.prototype.newQuery = function (entity) {
274+
var patchedQuery = newQuery.call(this, entity);
275+
// Only patch queries that are loading relations.
276+
var loadables = Object.keys(this.load);
277+
if (loadables.length > 0) {
278+
patchedQuery.softDeleteSelectFilter = this.softDeleteSelectFilter;
279+
if (entity && entity !== this.entity && this.model.hasPivotFields()) {
280+
var fields = this.model.pivotFields().reduce(function (fields, field) {
281+
Object.keys(field).filter(function (entity) { return loadables.includes(entity); }).forEach(function (entity) {
282+
fields.push(field[entity].pivot.entity);
283+
});
284+
return fields;
285+
}, []);
286+
// Release an entity that is an intermediate to a loadable relation.
287+
if (fields.includes(entity)) {
288+
patchedQuery.softDeleteSelectFilter = false;
289+
}
290+
}
291+
}
292+
return patchedQuery;
293+
};
267294
/**
268295
* Fetch all soft deletes from the store and group by entity.
269296
*/
@@ -284,11 +311,11 @@
284311
var _this = this;
285312
return models.filter(function (model) {
286313
// Only soft deletes
287-
if (_this.softDeletesFilter === true) {
314+
if (_this.softDeleteSelectFilter === true) {
288315
return model.$trashed();
289316
}
290317
// Include soft deletes
291-
if (_this.softDeletesFilter === false) {
318+
if (_this.softDeleteSelectFilter === false) {
292319
return models;
293320
}
294321
// Exclude soft deletes

0 commit comments

Comments
 (0)