jupiterjs/jquerymx — Issue #83: Model#isDirty returns true if Class.attributes were changed between #backup() and #isDirty() calls
Author: skhilko
Created: 2011-10-20 21:41:13+00:00
State: open

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.