masterrecord 0.3.64 → 0.3.65
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.
- package/deleteManager.js +33 -12
- package/package.json +1 -1
package/deleteManager.js
CHANGED
|
@@ -77,19 +77,26 @@ class DeleteManager {
|
|
|
77
77
|
|
|
78
78
|
// Check if this is a relationship that needs cascade deletion
|
|
79
79
|
if (this._isRelationshipType(propertyConfig.type)) {
|
|
80
|
-
|
|
80
|
+
// Read the backing field directly to avoid triggering lazy-loading
|
|
81
|
+
// getters, which can return Promises or error strings
|
|
82
|
+
const relatedModel = entity.__proto__
|
|
83
|
+
? entity.__proto__["_" + property]
|
|
84
|
+
: entity["_" + property];
|
|
81
85
|
|
|
82
86
|
if (relatedModel === null || relatedModel === undefined) {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
// Unloaded relationships are safe to skip — the database
|
|
88
|
+
// handles FK constraints; only cascade explicitly loaded data
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Only cascade into values that are actual tracked entities
|
|
93
|
+
if (Array.isArray(relatedModel)) {
|
|
94
|
+
for (const item of relatedModel) {
|
|
95
|
+
if (item && item.__entity) {
|
|
96
|
+
await this.cascadeDelete(item);
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
|
-
} else {
|
|
92
|
-
// Recursively delete related entities
|
|
99
|
+
} else if (relatedModel && relatedModel.__entity) {
|
|
93
100
|
await this.cascadeDelete(relatedModel);
|
|
94
101
|
}
|
|
95
102
|
}
|
|
@@ -129,9 +136,23 @@ class DeleteManager {
|
|
|
129
136
|
const propertyConfig = entity.__entity[property];
|
|
130
137
|
|
|
131
138
|
if (this._isRelationshipType(propertyConfig.type)) {
|
|
132
|
-
|
|
139
|
+
// Read backing field directly to avoid triggering lazy-loading getters
|
|
140
|
+
const relatedModel = entity.__proto__
|
|
141
|
+
? entity.__proto__["_" + property]
|
|
142
|
+
: entity["_" + property];
|
|
143
|
+
|
|
144
|
+
if (relatedModel === null || relatedModel === undefined) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
// Only cascade into actual tracked entities
|
|
149
|
+
if (Array.isArray(relatedModel)) {
|
|
150
|
+
for (const item of relatedModel) {
|
|
151
|
+
if (item && item.__entity) {
|
|
152
|
+
await this.cascadeDelete(item);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else if (relatedModel && relatedModel.__entity) {
|
|
135
156
|
await this.cascadeDelete(relatedModel);
|
|
136
157
|
}
|
|
137
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.65",
|
|
4
4
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
5
5
|
"main": "MasterRecord.js",
|
|
6
6
|
"bin": {
|