masterrecord 0.3.63 → 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.
@@ -44,6 +44,7 @@ class EntityTrackerModel {
44
44
  modelClass["__proto__"]["_" + modelField] = transformedValue;
45
45
 
46
46
  Object.defineProperty(modelClass,modelField, {
47
+ enumerable: true,
47
48
  set: function(value) {
48
49
  // Run validators before setting value
49
50
  const fieldDef = currentEntity[modelField];
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
- const relatedModel = entity[property];
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
- // Check if relationship is required (not nullable)
84
- if (!propertyConfig.nullable) {
85
- throw new Error(
86
- `Cannot delete ${entity.__entity.__name}: ` +
87
- `required relationship '${property}' is null. ` +
88
- `Set nullable: true if this is intentional.`
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
- const relatedModel = entity[property];
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
- if (relatedModel !== null && relatedModel !== undefined) {
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.63",
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": {