diff --git a/app/RSpade/Core/Js/Rsx_Js_Model.js b/app/RSpade/Core/Js/Rsx_Js_Model.js index d4aef06af..bebabbf90 100755 --- a/app/RSpade/Core/Js/Rsx_Js_Model.js +++ b/app/RSpade/Core/Js/Rsx_Js_Model.js @@ -29,6 +29,27 @@ class Rsx_Js_Model { // This constructor filters out the __MODEL marker that was used to identify which class // to instantiate, keeping only the actual data properties on the instance. const { __MODEL, ...modelData } = data; + + // Check for property conflicts before assignment + const modelName = __MODEL || this.constructor.name; + for (const key in modelData) { + if (key in this) { + if (typeof this[key] === 'function') { + throw new Error( + `Model property conflict: "${key}" from server response would overwrite ` + + `a method on ${modelName}. Check the PHP model's fetch() or toArray() method ` + + `to see if "${key}" should be excluded or renamed. If the JS method ${key}() ` + + `is computing a value the server now provides, remove the JS method.` + ); + } else { + throw new Error( + `Model property conflict: "${key}" already exists on ${modelName} ` + + `and would be overwritten by server response data.` + ); + } + } + } + Object.assign(this, modelData); }