Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return one object when specific their is a query param #406

Closed
benoittgt opened this issue Nov 27, 2015 · 6 comments
Closed

Return one object when specific their is a query param #406

benoittgt opened this issue Nov 27, 2015 · 6 comments

Comments

@benoittgt
Copy link

Hello

My json api endpoint looks like this api/front/devices?users=:user_id. For the moment in my config I have something like :

  this.get('/api/front/devices', function(db, request) {
      let userId = request.queryParams.user; // but what for?

      return {
        data: {
          type: 'devices',
          id: ??, //which id because is determine by the endpoint ?
          attributes: db.devices.find(??)
        }
      };
  });

If I set the id: 1 and .find(1). I get TypeError: Ember.A(...).mapBy is not a function

@benoittgt benoittgt changed the title Return one object when specific query param Return one object when specific their is a query param Nov 27, 2015
@benoittgt
Copy link
Author

TypeError: Ember.A(...).mapBy is not a function seems unrelated to the mirage configuration. Close it for now.

@sirvine
Copy link

sirvine commented Nov 27, 2015

It looks like you're returning a single object, but your query to the api/front/devices endpoint is expected to return a collection. Try returning in a format similar to this one:

return {
    data: db.devises.map(attrs => (
      {type: 'devises', id: attrs.id, attributes: attrs }
    ))
  };

@benoittgt
Copy link
Author

Thanks @sirvine. It appears the errors was related to this issue. I've updated my ember data and change my query to queryRecord and it's work like I want.

BTW in your exemple you're still few elements?

@benoittgt
Copy link
Author

Thanks

I've edited a little bit you answer s/devise/device and it's work perfectly in my test. Cheers

@sirvine
Copy link

sirvine commented Nov 27, 2015

Sorry, I had the devise library on my mind!

@aelkz
Copy link

aelkz commented Feb 7, 2017

//return this.store.findRecord('product', params.id); // NOT WORKING
return this.store.queryRecord('product', params.id); // WORKING

@sirvine sollution don't works with me. The error still showing on console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants