Add property conflict detection to JS ORM model hydration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-19 08:58:34 +00:00
parent dbc759a012
commit 3cc590186a

View File

@@ -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);
}