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

update coalesceFindRequests doc for JSONAPIAdapter #3771

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/ember-data/lib/adapters/json-api-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,55 @@ export default RESTAdapter.extend({
return hash;
},

/**
By default the JSONAPIAdapter will send each find request coming from a `store.find`
or from accessing a relationship separately to the server. If your server supports passing
ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
within a single runloop.

For example, if you have an initial payload of:

```javascript
{
post: {
id: 1,
comments: [1, 2]
}
}
```

By default calling `post.get('comments')` will trigger the following requests(assuming the
comments haven't been loaded before):

```
GET /comments/1
GET /comments/2
```

If you set coalesceFindRequests to `true` it will instead trigger the following request:

```
GET /comments?filter[id]=1,2
```

Setting coalesceFindRequests to `true` also works for `store.find` requests and `belongsTo`
relationships accessed within the same runloop. If you set `coalesceFindRequests: true`

```javascript
store.findRecord('comment', 1);
store.findRecord('comment', 2);
```

will also send a request to: `GET /comments?filter[id]=1,2`

Note: Requests coalescing rely on URL building strategy. So if you override `buildURL` in your app
`groupRecordsForFindMany` more likely should be overridden as well in order for coalescing to work.

@property coalesceFindRequests
@type {boolean}
*/
coalesceFindRequests: false,

/**
@method findMany
@param {DS.Store} store
Expand Down