store.query response expected to be an array but it was a single record

时间:2016-08-31 18:47:20

标签: ember.js ember-data

I am making an API call to get the conference rooms that match the profided filters. The response is returning an array, however Ember is giving me the error:

Error while processing route: rooms Assertion Failed: The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use store.queryRecord to query for a single record.

I am using RESTAdapter.

What am I doing wrong?

route:

import Ember from 'ember';

export default Ember.Route.extend({
  model(){
    return this.store.query('room', { filter: { option1: 'x', option2: 'y' } }).then(function(rooms) {
        return rooms;
    });
  }
});

Returned by server:

{"rooms":[
    {"id":"1","size":"600","title":"Centennial Room","description":""},
    {"id":"3","size":"1500","title":"Grand Auditorium","description":""}
]
}

Thank you.

1 个答案:

答案 0 :(得分:1)

问题在于多元化。我使用了广告连播,文件夹的名称(以及模型的名称和网址)为rooms。我将其更改为room,错误就消失了。

还有一个灰烬警告,但我忽略了它,而是注意错误。修复警告可以修复错误。