Skip to content

Commit

Permalink
Differentiate when a promise/record is returned (#107)
Browse files Browse the repository at this point in the history
Follow up on #106
  • Loading branch information
jpadilla authored and Jen Weber committed Jul 9, 2018
1 parent 8261a1d commit 5ab82d2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions guides/v3.3.0/models/finding-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,38 @@ Use [`store.findRecord()`](https://www.emberjs.com/api/ember-data/release/classe
This will return a promise that fulfills with the requested record:

```javascript
let blogPost = this.get('store').findRecord('blog-post', 1); // => GET /blog-posts/1
// GET /blog-posts/1
this.get('store').findRecord('blog-post', 1)
.then(function(blogPost) {
// Do something with `blogPost`
});
```

Use [`store.peekRecord()`](https://www.emberjs.com/api/ember-data/release/classes/DS.Store/methods/findRecord?anchor=peekRecord) to retrieve a record by its type and ID, without making a network request.
This will return the record only if it is already present in the store:

```javascript
let blogPost = this.get('store').peekRecord('blog-post', 1); // => no network request
// no network request
let blogPost = this.get('store').peekRecord('blog-post', 1);
```

### Retrieving Multiple Records

Use [`store.findAll()`](https://www.emberjs.com/api/ember-data/release/classes/DS.Store/methods/findAll?anchor=findAll) to retrieve all of the records for a given type:

```javascript
let blogPosts = this.get('store').findAll('blog-post'); // => GET /blog-posts
// GET /blog-posts
this.get('store').findAll('blog-post')
.then(function(blogPosts) {
// Do something with `blogPosts`
});
```

Use [`store.peekAll()`](http://emberjs.com/api/data/classes/DS.Store.html#method_peekAll) to retrieve all of the records for a given type that are already loaded into the store, without making a network request:

```javascript
let blogPosts = this.get('store').peekAll('blog-post'); // => no network request
// no network request
let blogPosts = this.get('store').peekAll('blog-post');
```

`store.findAll()` returns a `DS.PromiseArray` that fulfills to a `DS.RecordArray` and `store.peekAll` directly returns a `DS.RecordArray`.
Expand Down

0 comments on commit 5ab82d2

Please sign in to comment.