Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

Explain retrieval of related records #1705

Merged
merged 3 commits into from
Nov 1, 2016

Conversation

MarkMT
Copy link
Contributor

@MarkMT MarkMT commented Oct 19, 2016

This commit adds a sub-section to Models: Relationships to explain how to retrieve records from related models using the JSON API 'include' query parameter. This reflects recent changes to the DS.Store API documented in emberjs/data#4581

}).then(function(artists) {
return artists.get('firstObject');
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

return this.store.findRecord('post', params.post_id, {include: 'comments,comments.author'});
}
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

```
The post's comments would then be available in your template as `model.comments`.

Nested relationships can be specified in the `include` parameter as a dot-separated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break at period

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I meant not to break at "separated"

The post's comments would then be available in your template as `model.comments`.

Nested relationships can be specified in the `include` parameter as a dot-separated
sequence of relationship names. So to request both the post's comments and the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break at period

The value of the parameter should be a comma-separated list of names of the
relationships required.

If you are using an adapter that supports JSON API, such as Ember's default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break at comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I mean to break after the JSONAPIAdapter comma instead of at default

form part of that argument.
For example:

```js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javascript

import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model(params) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. I was following examples in the API docs which seem to use the longer form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API documentation isn't as evenly updated given its surface. I'll put it in the review queue!

import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model(params) {


```js
// GET to /artists?filter[name]=Adele&include=albums
adele = this.store.query('artist', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this example a model() hook as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is contrived of course, but a route targeting a specific record just seemed a little unlikely. But I'm happy to take guidance. If you'd prefer it framed as a model hook I'm happy to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, I did that in one of my first Ember apps ;P And I do it in a current app hehe, in an RSVP.hash. Thank you, the this.store bit doesn't make sense in a standalone setting, so framing it as a model() hook seems beneficial.

@locks
Copy link
Contributor

locks commented Oct 21, 2016

@MarkMT I think you missed two bits. Nearly there! :)

@MarkMT
Copy link
Contributor Author

MarkMT commented Oct 21, 2016

I guess I'm confused. The style guide says break at the beginning of every new sentence and
after the last comma in sentences over 120 characters. Maybe it's staring me in the face but what did I miss? The comma in 240 above isn't the last in the sentence. I see no period in the middle of a line near 262. Am I misinterpreting something?

The value of the parameter should be a comma-separated list of names of the
relationships required.

If you are using an adapter that supports JSON API, such as Ember's default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I mean to break after the JSONAPIAdapter comma instead of at default

```
The post's comments would then be available in your template as `model.comments`.

Nested relationships can be specified in the `include` parameter as a dot-separated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I meant not to break at "separated"

@MarkMT
Copy link
Contributor Author

MarkMT commented Oct 21, 2016

Ok, hope it's right now. Not sure I understand the requirements, but no problem. Seems to be a lot of inconsistency in the file as a whole.

@locks locks self-assigned this Oct 22, 2016
@MarkMT
Copy link
Contributor Author

MarkMT commented Oct 28, 2016

Is this good to go now?

@locks
Copy link
Contributor

locks commented Nov 1, 2016

Thanks for your contribution!

@homu r+

@homu
Copy link
Contributor

homu commented Nov 1, 2016

📌 Commit fa38033 has been approved by locks

homu added a commit that referenced this pull request Nov 1, 2016
Explain retrieval of related records

This commit adds a sub-section to Models: Relationships to explain how to retrieve records from related models using the JSON API 'include' query parameter. This reflects recent changes to the `DS.Store` API documented in emberjs/data#4581
@homu
Copy link
Contributor

homu commented Nov 1, 2016

⌛ Testing commit fa38033 with merge 0f37c86...

@homu
Copy link
Contributor

homu commented Nov 1, 2016

☀️ Test successful - status

@homu homu merged commit fa38033 into emberjs:master Nov 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants