1

Long story short, I'm trying to retrieve a single record in ember (more specifically a user object that contains vital information following a login).

However, when I try to use @store.find "user", query, I receive Error: Assertion Failed: The response from a findQuery must be an Array, not undefined

Any thoughts?

nicosuave
  • 13
  • 2

1 Answers1

0

Assuming you are querying for user type and query from above is a POJO your code may look like so:

var usersPromise = store.find('user', {foo:'bar', bla: 'baz'});

The response from your server would look something like this (note: users is plural), this is why you're receiving the error (ember.js Error: Assertion Failed: The response from a findAll must be an Array, not undefined).

{
  users: [
    {
      id: 1,
      name: 'Santa Clause'
    }
  ]
}

Since you are querying by POJO Ember assumes there are 0+ results. After the promise has resolved you can return the first object from that, since the collection will only have one.

usersPromise.then(function(users){
  return users.get('firstObject');
});

so in your case you would probably do something like this

this.store.find('user', {foo:'bar', bla: 'baz'}).then(function(users){
  return users.get('firstObject');
});
Community
  • 1
  • 1
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96