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

[DOC release] Update documentation for EmbeddedRecordsMixin. #3796

Merged
merged 1 commit into from
Sep 24, 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
22 changes: 11 additions & 11 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ var camelize = Ember.String.camelize;

`DS.EmbeddedRecordsMixin` supports serializing embedded records.

To set up embedded records, include the mixin when extending a serializer
To set up embedded records, include the mixin when extending a serializer,
then define and configure embedded (model) relationships.

Below is an example of a per-type serializer ('post' type).
Below is an example of a per-type serializer (`post` type).

```app/serializers/post.js
import DS from 'ember-data';
Expand All @@ -24,8 +24,8 @@ var camelize = Ember.String.camelize;
```
Note that this use of `{ embedded: 'always' }` is unrelated to
the `{ embedded: 'always' }` that is defined as an option on `DS.attr` as part of
defining a model while working with the ActiveModelSerializer. Nevertheless,
using `{ embedded: 'always' }` as an option to DS.attr is not a valid way to setup
defining a model while working with the `ActiveModelSerializer`. Nevertheless,
using `{ embedded: 'always' }` as an option to `DS.attr` is not a valid way to setup
embedded records.

The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for:
Expand All @@ -42,13 +42,13 @@ var camelize = Ember.String.camelize;
A resource's `attrs` option may be set to use `ids`, `records` or false for the
`serialize` and `deserialize` settings.

The `attrs` property can be set on the ApplicationSerializer or a per-type
The `attrs` property can be set on the `ApplicationSerializer` or a per-type
serializer.

In the case where embedded JSON is expected while extracting a payload (reading)
the setting is `deserialize: 'records'`, there is no need to use `ids` when
extracting as that is the default behavior without this mixin if you are using
the vanilla EmbeddedRecordsMixin. Likewise, to embed JSON in the payload while
the vanilla `EmbeddedRecordsMixin`. Likewise, to embed JSON in the payload while
serializing `serialize: 'records'` is the setting to use. There is an option of
not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you
do not want the relationship sent at all, you can use `serialize: false`.
Expand All @@ -65,13 +65,13 @@ var camelize = Ember.String.camelize;

Embedded records must have a model defined to be extracted and serialized. Note that
when defining any relationships on your model such as `belongsTo` and `hasMany`, you
should not both specify `async:true` and also indicate through the serializer's
should not both specify `async: true` and also indicate through the serializer's
`attrs` attribute that the related model should be embedded for deserialization.
If a model is declared embedded for deserialization (`embedded: 'always'`,
`deserialize: 'record'` or `deserialize: 'records'`), then do not use `async:true`.
If a model is declared embedded for deserialization (`embedded: 'always'` or `deserialize: 'records'`),
then do not use `async: true`.

To successfully extract and serialize embedded records the model relationships
must be setup correcty See the
must be setup correcty. See the
[defining relationships](/guides/models/defining-models/#toc_defining-relationships)
section of the **Defining Models** guide page.

Expand Down Expand Up @@ -244,7 +244,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
comments: {embedded: 'always'}
comments: { embedded: 'always' }
}
})
```
Expand Down