Skip to content
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

Model#isDirty returns true if Class.attributes were changed between #backup() and #isDirty() calls #83

Open
skhilko opened this issue Oct 20, 2011 · 0 comments

Comments

@skhilko
Copy link

skhilko commented Oct 20, 2011

I'm not sure if it's a Model#isDirty bug or Model#serialize() related.
Please have a look at the situation:

  1. There is a model instance (a user) which we've backed up with $.Model#backup call. Model.User.attributes static property had the following set of attributes at that moment:
    { createdDate:"date", id:"string", modifiedDate: "date", name: "string" }
    This attributes definitions reflected on the _backupStore snapshot made with backup call.
  2. An Ajax call happened to retrieve other instances of users (Model.User.findAll()). This call returned a list of users which had more properties and they were added to the Class.attributes during conversion.
    { createdDate:"date", id:"string", modifiedDate: "date", name: "string", termsAcceptedOn: "date" // new attribute }
    The original user object was not touched on this step.
  3. Now we call isDirty() on the original object and it appears to be dirty because now it was serialized with new set of attributes.

So what could be wrong:

  1. Model#serialize() uses Class.attributes to serialize an object. Even if the object doesn't have an attribute, the attribute will be serialized as undefined in case it's defined in Class.attributes.
  2. Model#isDirty() uses its own same implementation which returns false in case the number of attributes on two objects is different. Absolutely the same objects, which were serialized on different points of time and have different number of undefined attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant