Skip to content

Commit

Permalink
[model,bugfix][s]: fix nasty subtle bug (1h+ to track down) whereby d…
Browse files Browse the repository at this point in the history
…ataset change event not being triggered on resource update.

* Details: discovered this because using fixtures dataset view was not showing resources. Tracked this to fact that on dataset.set with fixture data (of existing dataset -- one autocreated for view) change event was getting fired *before* _updateChildren called (or completed) and hence resources not being shown (as render happened before resources on object).
  • Loading branch information
rgrp committed Jul 28, 2011
1 parent 777a280 commit 149465f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/model.js
Expand Up @@ -129,8 +129,15 @@ CKAN.Model = function ($, _, Backbone, undefined) {
_createChildren: function () {
_.each(this.children, function (Model, key) {
if (!this.get(key)) {
this.attributes[key] = new Backbone.Collection();
this.attributes[key].model = Model;
var newColl = new Backbone.Collection();
this.attributes[key] = newColl;
newColl.model = Model;
// bind change events so updating the children trigger change on Dataset
var self = this;
// TODO: do we want to do all or be more selective
newColl.bind('all', function() {
self.trigger('change');
});
}
}, this);
return this;
Expand Down

0 comments on commit 149465f

Please sign in to comment.