Question

I try to create a record which has a oneToMany relationship like this :

App.Models.Esnode = DS.Model.extend({ nodeUrl: DS.attr('string'), nodeState: DS.attr('string'), indices: DS.hasMany(App.Models.Index) });

And

App.Models.Index = DS.Model.extend({
    name: DS.attr('string')
});

In the function model of the ApplicationRoute, I do this :

this.store.createRecord(App.Models.Esnode, {nodeUrl: "http://192.168.1.13:9200"});

Which gives the error :

Error while loading route: TypeError: Cannot read property 'links' of null

in the Ember data code at line 5938, in the method reloadHasManys :

if (this._data.links && this._data.links[name]) { return; }

And indeed this._data is undefined but should not be as the data ha not yet been initialized at this point in the createRecord method. I checked my mappings, tried different things but nothing worked. I didn't find anything on this problem. Did I do something wrong.

I am on the 1.5.1 of Ember and 1.0.0-beta.7.f87cba88 of Ember data

Was it helpful?

Solution

You should define your model in the App namespace and reference any relationships by their name, not the actual variable, like this:

App.Esnode = DS.Model.extend({ 
    nodeUrl: DS.attr('string'), 
    nodeState: DS.attr('string'), 
    indices: DS.hasMany('index') 
});

And then when you create a record, you pass in the string name of the type of record you're creating, like this:

this.store.createRecord('esnode',{
     nodeUrl: "http://192.168.1.13:9200"
});

That should fix your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top