getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Implement findMany to find multiple instances by pk at once #79

Open joostdevries opened 11 years ago

joostdevries commented 11 years ago

Can't find this in the roadmap but it's a pretty nice feature to have as it can severly reduce workload on the server in cases of hasMany relations with lots of FK's.

This idea is pretty simple, if session.find('group',1) would return this JSON...

{
   "group": {
      "id": 1,
      "name": "Test group",
      "user_ids": [1, 2, 3]
   }
}

.. and my App.Group would have a relation users:Ep.hasMany(App.User), the adapter would make the following request: GET /users?ids[]=1&ids[]=2&ids[]=3

If this is something within scope I can probably create a PR with code as well.

ghempton commented 11 years ago

I think there are two features here:

  1. Providing a session level method findMany
  2. Having an adapter which is intelligent enough to utilize bulk backend APIs

I think both could be valuable. But should probably be treated separately.

jasonkriss commented 10 years ago

Just a small note/opinion on this. Any implementation of findMany should probably take a parent argument (group in this case). This would give the same benefit even if the api isn't completely flat. E.g. the request would then be: GET /group/1/users