Skip to content

is it possible set resource for specific json? #149

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

Closed
lichtner opened this issue Sep 11, 2014 · 4 comments
Closed

is it possible set resource for specific json? #149

lichtner opened this issue Sep 11, 2014 · 4 comments
Labels

Comments

@lichtner
Copy link

Hi, my json looks like:

{
  meta: { ... }
  list: [
   {id: 1, name: 'aaa'},
   {id: 2, name: 'bbb'},
   {id: 3, name: 'ccc'}
  ]
}

I don't known how to define DS.defineResource for this json

@jmdobry
Copy link
Member

jmdobry commented Sep 11, 2014

The json above is what your server returns when you do GET /user? What does your server return when you do GET /user/1?

@lichtner
Copy link
Author

yes this is GET /user and GET /user/1 return {id: 1, name: 'aaa'}. May be this is bad API pattern but I need some extra meta info for collection. For one record I don't need meta info.

@jmdobry
Copy link
Member

jmdobry commented Sep 11, 2014

Until #155 is done you would have to do the following when working with collections:

var User = DS.defineResource('user');

// cacheResponse: false, don't auto-inject items into the store
User.findAll({ ... }, { cacheResponse: false }).then(function (data) {
  // manually inject the users into the store
  User.inject(data.list);

  // now you can do
  User.get(1); // { id: 1, name: 'aaa' }
});

@lichtner
Copy link
Author

this works, thanks

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

No branches or pull requests

2 participants