jeudi 28 avril 2016

Ember-data: store.query properly returns array but still throws error 'expecting array, found single record'

I have the following express route for 'get all locations':

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));
});

And this ember model hook triggers it correctly:

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}))
}

Now, this query is sending a get request to the following url with params:

GET /locations?organization=571974742ce868d575b79d6a

And my server is returning a 200 success code but then the model hook is crashing with this error:

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.

Creating a postman request to the same address:

localhost:3200/locations?organization=571974742ce868d575b79d6a

I see an array returned, filled with the proper objects, like so:

[{object1}, {object2]

Which seems like the correct response. Why might Ember be telling me that it's only receiving a single record?

It even throws me this warning when the model hook is called:

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

Thanks for any wisdom you can lend here Ember folks!




Aucun commentaire:

Enregistrer un commentaire