Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions model/backup/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ See this in action:
* @parent jquerymx.model.backup
* Returns if the instance needs to be saved. This will go
* through associations too.
* @param {Boolean} [checkAssociations] Whether attributes which are nested models or
* objects are also checked.
* @return {Boolean} true if there are changes, false if otherwise
*/
isDirty: function(checkAssociations) {
Expand All @@ -119,6 +121,8 @@ See this in action:
* @function jQuery.Model.prototype.restore
* @parent jquery.model.backup
* restores this instance to its backup data.
* @param {Boolean} [restoreAssociations] Whether attributes which are nested models or
* objects are also restored.
* @return {model} the instance (for chaining)
*/
restore: function(restoreAssociations) {
Expand Down
19 changes: 18 additions & 1 deletion model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,13 @@ steal('jquery/class', 'jquery/lang/string', function() {
args, globalArgs, callback = success,
list = Class.list;

// If the property is a nested model, assign the value(s) using its attrs method
// if the new value is an object.
if (this._isModel(property) && $.isPlainObject(value)) {
this[property].attrs( value );
return;
}

// set the property value
// notice that even if there's an error
// property values get set
Expand Down Expand Up @@ -1452,6 +1459,16 @@ steal('jquery/class', 'jquery/lang/string', function() {

},

/**
* Determine whether a property of this model is an association, i.e. another nested model.
* @hide
* @param {String} prop The property to test.
* @return {Boolean} Is it a model or not.
*/
_isModel : function(prop) {
return !!(this[prop] && this[prop].Class && this[prop].Class._models);
},

/**
* Removes an attribute from the list existing of attributes.
* Each attribute is set with [jQuery.Model.prototype.attr attr].
Expand Down Expand Up @@ -1848,4 +1865,4 @@ steal('jquery/class', 'jquery/lang/string', function() {
* - <code>deferred</code> - A deferred that gets resolved to any additional attrs
* that might need to be set on the model instance.
*/
});
});