@codenameryuu/adonis-lucid-auto-preload 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -61,6 +61,11 @@ export declare function AutoPreload<T extends NormalizeConstructor<LucidModel>>(
|
|
|
61
61
|
toAttributes(): Record<string, any>;
|
|
62
62
|
related<Name extends undefined>(relation: Name): NonNullable</*elided*/ any[Name]> extends import("@adonisjs/lucid/types/relations").ModelRelations<LucidModel, LucidModel> ? (import("@adonisjs/lucid/types/relations").ModelRelations<LucidModel, LucidModel> & /*elided*/ any[Name] & {})["client"] : never;
|
|
63
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Propagate query flags used by other mixins (e.g. SoftDeletes) to preload builders.
|
|
66
|
+
* SoftDeletes uses `query.ignoreDeleted = false` for `.withTrashed()` / `.onlyTrashed()`.
|
|
67
|
+
*/
|
|
68
|
+
inheritQueryFlags(parent: any, child: any): void;
|
|
64
69
|
/**
|
|
65
70
|
* List of relationships to auto-preload.
|
|
66
71
|
*/
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
export function AutoPreload(superclass) {
|
|
2
2
|
class AutoPreloadModel extends superclass {
|
|
3
|
+
/**
|
|
4
|
+
* Propagate query flags used by other mixins (e.g. SoftDeletes) to preload builders.
|
|
5
|
+
* SoftDeletes uses `query.ignoreDeleted = false` for `.withTrashed()` / `.onlyTrashed()`.
|
|
6
|
+
*/
|
|
7
|
+
static inheritQueryFlags(parent, child) {
|
|
8
|
+
if (!parent || !child)
|
|
9
|
+
return;
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(parent, 'ignoreDeleted') &&
|
|
11
|
+
parent.ignoreDeleted === false) {
|
|
12
|
+
if (typeof child.withTrashed === 'function') {
|
|
13
|
+
child.withTrashed();
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
child.ignoreDeleted = false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
3
20
|
/**
|
|
4
21
|
* List of relationships to auto-preload.
|
|
5
22
|
*/
|
|
@@ -47,7 +64,9 @@ export function AutoPreload(superclass) {
|
|
|
47
64
|
this.handleNestedPreload(query, relation.split('.'));
|
|
48
65
|
}
|
|
49
66
|
else {
|
|
50
|
-
query.preload(relation)
|
|
67
|
+
query.preload(relation, (builder) => {
|
|
68
|
+
this.inheritQueryFlags(query, builder);
|
|
69
|
+
});
|
|
51
70
|
}
|
|
52
71
|
}
|
|
53
72
|
else if (typeof relation === 'function') {
|
|
@@ -60,6 +79,7 @@ export function AutoPreload(superclass) {
|
|
|
60
79
|
if (!current)
|
|
61
80
|
return;
|
|
62
81
|
query.preload(current, (builder) => {
|
|
82
|
+
this.inheritQueryFlags(query, builder);
|
|
63
83
|
if (parts.length > 0) {
|
|
64
84
|
this.handleNestedPreload(builder, [...parts]);
|
|
65
85
|
}
|
package/package.json
CHANGED