DS.EmbeddedRecordsMixin Class packages/activemodel-adapter/lib/system/embedded_records_mixin.js:4


The EmbeddedRecordsMixin allows you to add embedded record support to your serializers. To set up embedded records, you include the mixin into the serializer and then define your embedded relations.

1
2
3
4
5
App.PostSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    comments: {embedded: 'always'}
  }
})

Currently only {embedded: 'always'} records are supported.

Show:

extractArray

Extract embedded objects out of a standard payload and add them as sideloaded objects instead.

extractSingle

Extract embedded objects out of the payload for a single object and add them as sideloaded objects instead.

keyForAttribute

(attribute)

Converts camelcased attributes to underscored when serializing.

Parameters:

attribute String

Returns:

String

keyForRelationship

(key, kind)

Underscores relationship names and appends "id" or "ids" when serializing relationship keys.

Parameters:

key String
kind String

Returns:

String

normalize

(type, hash, prop)

Add extra step to DS.RESTSerializer.normalize so links are normalized.

If your payload looks like this

1
2
3
4
5
6
7
{
  "post": {
    "id": 1,
    "title": "Rails is omakase",
    "links": { "flagged_comments": "api/comments/flagged" }
  }
}

The normalized version would look like this

1
2
3
4
5
6
7
{
  "post": {
    "id": 1,
    "title": "Rails is omakase",
    "links": { "flaggedComments": "api/comments/flagged" }
  }
}

Parameters:

type subclass of DS.Model
hash Object
prop String

Returns:

Object

normalizeLinks

(hash)

Convert snake_cased links to camelCase

Parameters:

hash Object

normalizeRelationships

private

Normalize the polymorphic type from the JSON.

Normalize: js { id: "1" minion: { type: "evil_minion", id: "12"} }

To: js { id: "1" minion: { type: "evilMinion", id: "12"} }

serializeHasMany

Serialize has-may relationship when it is configured as embedded objects.

serializeIntoHash

(hash, type, record, options)

Underscores the JSON root keys when serializing.

Parameters:

hash Object
type subclass of DS.Model
record DS.Model
options Object

serializePolymorphicType

(record, json, relationship)

Serializes a polymorphic type as a fully capitalized model name.

Parameters:

record DS.Model
json Object
relationship

typeForRoot

(root)

Extracts the model typeKey from underscored root objects.

Parameters:

root String

Returns:

String the model's typeKey