Reputation: 9537
I use Ember Data 1.0.0-beta.14.1 with Ember 1.9.1 at the moment (with Ember-cli). Somehow one of my collections doesn't work anymore since i update from an older ember data version.
I got a DirectoryModel (for a filesystem). Directories can have subdirectories and files.
import DS from 'ember-data';
var DirectoryModel = DS.Model.extend({
...
parent: DS.belongsTo('directory', { async: true, inverse: 'children' }),
children: DS.hasMany('directory', { async: true, readOnly: true, inverse: 'parent' }),
files: DS.hasMany('file', { async: true, readOnly: true })
});
A got a serializer to load the hashMany releationships:
export default ApplicationSerializer.extend({
normalizePayload: function(payload) {
payload.directories.forEach(function(directory) {
directory.links = {
children: '/link-to-server'),
files: 'link-to-server')
};
});
return this._super.apply(this,arguments);
}
});
My view:
//WORKS GREAT
{{#each directory in children itemController="file-directory"}}
...
{{/each}}
CREATES ERRORS
{{#each file in files }}
...
{{/each}}
Somehow that files loop ends up to an error. It looks like question "Cannot call method 'destroy' of undefined" in arrayWillChange, only in my case I just load the data from the server. I don't understand what i did wrong, as the children-relation does work well. In older versions this just works, but with Ember Data 1.0.0-beta.14.1 it doesn't...
I looked at the ember code at the arrayWillChange
function, and saw that this._childViews
was just an empty array. But if I set a breakpoint and executed this.get('content.content').toArray()
in my console, I saw an array with one element. Somehow/somewhere it seems the data is out of sync...
Upvotes: 1
Views: 3478
Reputation: 9537
In the end it was a bug in Ember Data 1.0.0-beta.14.1. It's solved in the next version, Ember Data 1.0.0-beta.15: https://github.com/emberjs/data/issues/2662
Upvotes: 2
Reputation: 1173
I'm was getting the same error and I also use links to load data. What I accidentally found out is that wrapping arrays in something like
files: function() {
return this.get('directory.files').map(function(file) { return file; });
}.property('directory.files.@each')
solves the issue.
Have no idea why it works :)
Upvotes: 1