1

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...

1
  • I've gotten this error recently due to a virtual view naming conflict when inside a component's layout template. However, without more context it's not possible to help you; consider writing a jsbin the reproduces the error. Commented Jan 15, 2015 at 19:36

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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 :)

1 Comment

Problem was the internal Ember Data function arrayContentDidChange was sometimes incorrectly triggered (see github.com/emberjs/data/pull/2723). Creating a map probably prevents calling this function at the wrong time. Anyway, problem is fixed with latest Ember Data version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.