-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defaults corruption #393
Comments
Make it function that returns object. On 5 April 2014 08:30, Ruben Rodriguez [email protected] wrote:
|
This is an excerpt from docs/schema.md:
Take a look at |
Yup, makes sense. |
Any defaults that contain a reference will be corrupted when a value is set into the corresponding attribute. Here's a short example:
...and in JS in case you hate Coffee:
You can see in model.js that the getDefault function simply returns the default, which in the case of Schema.JSON (and possibly others) is a reference to the default object. This means that when a key is set in a property of a specific model instance, the change will propagate up to (and corrupt) the default object.
I'm not sure what the correct fix is. I am working around this in my own code by using the function version of default, and returning an empty object from a simple closure.
The text was updated successfully, but these errors were encountered: