Trouble getting a simple ember data working

Hi all, i am getting the below message when i try to work on simple example using ember data. please help/suggest how to fix the problem.

WARNING: Encountered “0” in payload, but no model was found for model name “0” (resolved model name using test-emberdata@serializer:rotation-group:.modelNameFromPayloadKey(“0”))

below is the response from api.

[ { “groupIndex”:1, “creativeIds”:[ 1, 2 ] }, { “groupIndex”:2, “creativeIds”:[ 3, 4 ] } ]

code:

model: rotation-group.js.

import DS from ‘ember-data’;

export default DS.Model.extend({

 groupIndex: DS.attr('number'),
 creativeIds: DS.attr('array')

});

adapter: rotation-group.js

import Ember from ‘ember’;

import DS from ‘ember-data’;

export default DS.RESTAdapter.extend({

findAll: function(store, type, query, record) {
	let url = "http://localhost:3000/api/rotationGroups";
	return this.ajax(url, 'POST');
}

});

routes/test.js import Ember from ‘ember’;

export default Ember.Route.extend({

model: function(){
    return this.store.findAll('rotationGroup')
}

});

@rytis @square

It’s happening because your backend is sending you rootless JSON

can i do some thing from client side ?

I tried to normalize like below, still the same problem

import Ember from ‘ember’;

import DS from ‘ember-data’;

export default DS.RESTSerializer.extend({

normalizeResponse: function(store, primaryModelClass, payload, id, requestType){
 payload.forEach((item, idx) => {
  item.id = 'rotationGroup'+idx;
 })
 payload = {
   id: 'rotationGroup',
   data: payload
 };
 return this._super(...arguments);
 }
});

In your application serializer do :

export default DS.RESTSerializer.extend({
normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
        let typeKey = primaryModelClass.modelName;
        let ret = {};
        ret[typeKey] = payload;
        return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, true);
    },
    normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
        let pluralTypeKey = Ember.Inflector.inflector.pluralize(primaryModelClass.modelName);
        let ret = {};
        ret[pluralTypeKey] = payload;
        return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, false);
    }
});

@jmimi Hi thanks for reply, I tried i get the below error now. ember.debug.js:27730 Error while processing route: test Assertion Failed: Unable to find transform for ‘array’ Error: Assertion Failed: Unable to find transform for ‘array’

Do you have array transformer?

@jmimi

Works now with small change to your code, need to add id. Thank you so much for your help.

 normalizeSingleResponse(store, primaryModelClass, payload, id, requestType){
let typeKey = primaryModelClass.modelName;
let ret = {};
payload.forEach((item, idx) => {
  item.id = idx;
});
ret[typeKey] = payload;
return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, true);

},

normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
let pluralTypeKey = Ember.Inflector.inflector.pluralize(primaryModelClass.modelName);
let ret = {};
payload.forEach((item, idx) => {
  item.id = idx;
});
ret[pluralTypeKey] = payload;
return this._normalizeResponse(store, primaryModelClass, ret, id, requestType, false);

},