Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

issue #19735: Fix problems in documents box caused by changes in the …

…way backbone relational works.
  • Loading branch information...
commit 743c3c5aa108faa9c441cbf97925c7d8e028ce17 1 parent 40db82d
John Rogelstad authored
View
2  lib/backbone-x/source/collection.js
@@ -200,7 +200,7 @@ white:true*/
i,
K = XM.Model;
for (i = 0; i < result.models.length; i += 1) {
- result.models[i].setStatus(K.READY_CLEAN, {cascade: true});
+ result.models[i].setStatus(K.READY_CLEAN, {propagate: true});
}
return result;
},
View
15 lib/backbone-x/source/model.js
@@ -378,7 +378,7 @@ white:true*/
if (klass.canRead()) {
this.setStatus(K.BUSY_FETCHING, {cascade: true});
- options.cascade = true; // Update status of children
+ options.propagate = true; // Update status of *all* relations
options.success = function (resp) {
model.setStatus(K.READY_CLEAN, options);
if (XT.debugging) {
@@ -1039,12 +1039,16 @@ white:true*/
`cascade` will propagate status recursively to all HasMany children.
@param {Number} Status
+ @params {Object} Options
+ @params {Boolean} [cascade=false] Cascade changes only through toMany relations
+ @params {Boolean} [propagate=false] Propagate changes through both toMany and toOne relations
*/
setStatus: function (status, options) {
var K = XM.Model,
attr,
that = this,
parent,
+ parentRelation,
setOptions = { force: true };
// Prevent recursion
@@ -1060,7 +1064,7 @@ white:true*/
}
// Cascade changes through relations if specified
- if (options && options.cascade) {
+ if (options && (options.cascade || options.propagate)) {
_.each(this.relations, function (relation) {
attr = that.attributes[relation.key];
if (attr && attr.models &&
@@ -1070,7 +1074,8 @@ white:true*/
model.setStatus(status, options);
}
});
- } else if (attr && relation.type === Backbone.HasOne) {
+ } else if (attr && options.propagate &&
+ relation.type === Backbone.HasOne) {
attr.setStatus(status, options);
}
});
@@ -1090,6 +1095,10 @@ white:true*/
// Percolate changes up to parent when applicable
if (parent && (this.isDirty() ||
status === K.DESTROYED_DIRTY)) {
+ parentRelation = _.find(this.relations, function (relation) {
+ return relation.isAutoRelation;
+ });
+ parent.changed[parentRelation.reverseRelation.key] = true;
parent.trigger('change', parent, options);
}
this.release();
View
4 lib/enyo-x/source/views/documents_box.js
@@ -223,7 +223,7 @@ trailing:true white:true*/
idFetched = function () {
model.off('change:id', idFetched);
model.set('purpose', purpose, {silent: true});
- model.set(infoAttr, selectedModel, {silent: true});
+ model.set(infoAttr, selectedModel.attributes, {silent: true});
collection.add(model);
};
model.on('change:id', idFetched);
@@ -277,7 +277,7 @@ trailing:true white:true*/
// First load up the info model version
// of the model just created
var Klass = XT.getObjectByName(infoModel),
- info = new Klass({id: model.id}),
+ info = Klass.findOrCreate({id: model.id}),
options = {};
options.success = function () {
Please sign in to comment.
Something went wrong with that request. Please try again.