灰烬数据:store.query正确返回数组,但仍然抛出错误“期望数组,找到单个记录”

Dan*_*son 0 ember.js ember-data

对于“获取所有位置”,我有以下明确的路线:

router.get('/', function(req, res){

    let q = req.query;

    let locations = Location.find({organization: q.organization});

    locations.then(r => res.status(200).send(r))
        .catch(err => res.status(500).send(err));
});
Run Code Online (Sandbox Code Playgroud)

这个ember模型钩子可以正确触发它:

model(){
    return this.store.findRecord("user", this.get('session.currentUser.id'))
      .then(user => user.get('organization'))
      .then(org => this.store.query("location", {organization: org.id}))
}
Run Code Online (Sandbox Code Playgroud)

现在,此查询正在使用参数将获取请求发送到以下URL:

GET /locations?organization=571974742ce868d575b79d6a
Run Code Online (Sandbox Code Playgroud)

我的服务器返回200成功代码,但是模型挂钩因以下错误而崩溃:

query to locations failed with error: Error: 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.
Run Code Online (Sandbox Code Playgroud)

创建到同一地址的邮递员请求:

localhost:3200/locations?organization=571974742ce868d575b79d6a
Run Code Online (Sandbox Code Playgroud)

我看到返回的数组充满了适当的对象,如下所示:

[{object1}, {object2]
Run Code Online (Sandbox Code Playgroud)

这似乎是正确的回应。为什么Ember会告诉我它只收到一条记录?

调用模型挂钩时,它甚至向我抛出此警告:

WARNING: Encountered "0" in payload, but no model was found for model name "0" (resolved model name using lc-dash@serializer:application:.modelNameFromPayloadKey("0"))
Run Code Online (Sandbox Code Playgroud)

编辑:

意识到这可能是序列化器/适配器错误:

// app/adapters/application.js

import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DS.RESTAdapter.extend(DataAdapterMixin, {
    host: 'http://localhost:3200',
    authorizer: 'authorizer:application'
});
Run Code Online (Sandbox Code Playgroud)

序列化器可能缺少某些内容?

// app/serializers/application.js

import DS from 'ember-data';

export default DS.RESTSerializer.extend({});
Run Code Online (Sandbox Code Playgroud)

Gau*_*rav 5

RESTSerializer期望在与多个模型名称匹配的有效负载密钥内传递对象数组:

{
  "organizations": [
    {
      "id": 1,
      "key1": "value1",
      "key2": "value2"
    },
    {
      "id": 2,
      "key1": "value3",
      "key2": "value4"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

或者,JsonSerializer如果您不想发送有效载荷密钥,则可以使用。