Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js error while loading route
    primarykey
    data
    text
    <p>I have an ember app with two models, user and subject, both of which rely on an api for data. The JSON returned is not in the format that ember expects, so I have a custom serializer for each model-</p> <pre><code>var foo = { 'App.Subject': {'single':'subject','array':'subjects'} }; App.SubjectSerializer = DS.RESTSerializer.extend({ extractSingle: function(store, type, payload, id, requestType) { var p = {}; p[foo[type]['single']] = payload; return this._super(store, type, p, id, requestType); }, extractArray: function(store, type, payload, id, requestType) { var p = {}; p[foo[type]['array']] = payload; return this._super(store, type, p, id, requestType); }, serializeIntoHash: function(hash, type, record, options) { Ember.merge(hash, this.serialize(record, options)); } }); </code></pre> <p>This works perfectly. However, I have a similar serializer for my Users model-</p> <pre><code>var foo = { 'App.User': {'single':'user','array':'users'} }; App.UserSerializer = DS.RESTSerializer.extend({ extractSingle: function(store, type, payload, id, requestType) { var p = {}; p[foo[type]['single']] = payload; return this._super(store, type, p, id, requestType); }, extractArray: function(store, type, payload, id, requestType) { var p = {}; p[foo[type]['array']] = payload; return this._super(store, type, p, id, requestType); }, serializeIntoHash: function(hash, type, record, options) { Ember.merge(hash, this.serialize(record, options)); } }); </code></pre> <p>When I try to access my users in the browser, I get this error:</p> <blockquote> <p>Assertion failed: Error while loading route: TypeError: Cannot read property 'array' of undefined</p> </blockquote> <p>Can anyone help?</p> <p>EDIT: 'type' in the extractArray function refers to the root property of the JSON, eg if my JSON was </p> <pre><code>{ "user": { name: "xyz", email: "xyz@wxy.com" } } </code></pre> <p>the 'type' would be 'user'.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload