vendor/components/indefinido-indemma/build/release.js in ende-0.4.18 vs vendor/components/indefinido-indemma/build/release.js in ende-0.4.19
- old
+ new
@@ -20175,11 +20175,12 @@
data[_name = this.parent_resource] || (data[_name] = this.parent);
return model[model.singularize(this.resource)](data);
},
push: function() {
console.warn("" + this.resource + ".push is deprecated and will be removed, please use add instead");
- return Array.prototype.push.apply(this, arguments);
+ Array.prototype.push.apply(this, arguments);
+ return arguments[0];
},
length: 0,
json: function(methods, omissions) {
var record, _i, _len, _results;
@@ -20187,11 +20188,22 @@
for (_i = 0, _len = this.length; _i < _len; _i++) {
record = this[_i];
_results.push(record.json(methods, omissions));
}
return _results;
- }
+ },
+ find: function(id) {
+ var resource, _i, _len;
+
+ for (_i = 0, _len = this.length; _i < _len; _i++) {
+ resource = this[_i];
+ if (resource._id === id) {
+ return resource;
+ }
+ }
+ },
+ filter: Array.prototype.filter || (typeof _ !== "undefined" && _ !== null ? _.filter : void 0)
};
singular = {
create: function(data) {
return model[this.resource].create(extend({}, this, data));
@@ -20921,11 +20933,11 @@
promise.done(param);
}
return promise;
},
assign_attributes: function(attributes) {
- var association, association_attributes, association_name, associations_attributes, attribute, message, name, singular_resource, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;
+ var association, association_attributes, association_name, associations_attributes, attribute, message, name, singular_resource, _base, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results;
_ref = model[this.resource.toString()].has_many;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
association_name = _ref[_i];
associations_attributes = attributes[association_name];
@@ -20965,10 +20977,20 @@
delete attributes[association_name + "_attributes"];
if (association_attributes) {
this[association_name] = this["build_" + association_name](association_attributes);
}
}
+ _ref3 = model[this.resource.toString()].belongs_to;
+ for (_m = 0, _len4 = _ref3.length; _m < _len4; _m++) {
+ association_name = _ref3[_m];
+ association_attributes = (_ref4 = typeof (_base = attributes[association_name]).json === "function" ? _base.json() : void 0) != null ? _ref4 : attributes[association_name];
+ delete attributes[association_name];
+ delete attributes[association_name + "_attributes"];
+ if (association_attributes) {
+ this[association_name] = this["build_" + association_name](association_attributes);
+ }
+ }
_results = [];
for (name in attributes) {
attribute = attributes[name];
if (attribute !== this[name]) {
if (type(attribute) === 'object') {
@@ -21479,15 +21501,17 @@
data = void 0;
}
promises.push(this.scope.fetch.call(this, data, null, scopable.record.failed));
reload = $.when.apply(jQuery, promises);
reload.done(function(records, status) {
- var association_name, singular_resource, _i, _j, _len, _len1, _ref;
+ var association_name, create, index, singular_resource, target, _i, _j, _k, _len, _len1, _len2, _ref;
- Array.prototype.splice.call(this, 0);
if (!records.length) {
- return;
+ if (this.length) {
+ Array.prototype.splice.call(this, 0);
+ }
+ return true;
}
singular_resource = model.singularize(this.resource);
for (_i = 0, _len = records.length; _i < _len; _i++) {
record = records[_i];
_ref = model[singular_resource].has_many;
@@ -21495,10 +21519,19 @@
association_name = _ref[_j];
record["" + association_name + "_attributes"] = record[association_name];
delete record[association_name];
}
}
- this.add.apply(this, records);
+ create = [];
+ for (index = _k = 0, _len2 = records.length; _k < _len2; index = ++_k) {
+ record = records[index];
+ if (target = this.find(record._id)) {
+ target.assign_attributes(record);
+ } else {
+ create.push(record);
+ }
+ }
+ this.add.apply(this, create);
records.splice(0);
return records.push.apply(records, this);
});
reload.done(done);
reload.fail(fail);