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] shorthand methods and quotes for json-api serializer #4778

Merged
merged 3 commits into from
Jan 27, 2017
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
48 changes: 22 additions & 26 deletions addon/serializers/json-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@ const dasherize = Ember.String.dasherize;

This serializer normalizes a JSON API payload that looks like:

```js

// models/player.js
import DS from "ember-data";

export default DS.Model.extend({
name: DS.attr(),
skill: DS.attr(),
gamesPlayed: DS.attr(),
club: DS.belongsTo('club')
});
```app/models/player.js
import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
skill: DS.attr('string'),
gamesPlayed: DS.attr('number'),
club: DS.belongsTo('club')
});
```

// models/club.js
import DS from "ember-data";
```app/models/club.js
import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr(),
location: DS.attr(),
players: DS.hasMany('player')
});
export default DS.Model.extend({
name: DS.attr('string'),
location: DS.attr('string'),
players: DS.hasMany('player')
});
```

```js

{
"data": [
{
Expand Down Expand Up @@ -104,7 +102,6 @@ const dasherize = Ember.String.dasherize;

```app/serializers/application.js
export default JSONAPISerializer.extend({

normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
let normalizedDocument = this._super(...arguments);

Expand All @@ -122,7 +119,6 @@ const dasherize = Ember.String.dasherize;

return normalizedRelationship;
}

});
```

Expand Down Expand Up @@ -439,7 +435,7 @@ const JSONAPISerializer = JSONSerializer.extend({
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
keyForAttribute: function(attr, method) {
keyForAttribute(attr, method) {
return Ember.String.dasherize(attr).toUpperCase();
}
});
Expand Down Expand Up @@ -469,7 +465,7 @@ const JSONAPISerializer = JSONSerializer.extend({
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
keyForRelationship: function(key, relationship, method) {
keyForRelationship(key, relationship, method) {
return Ember.String.underscore(key);
}
});
Expand Down Expand Up @@ -653,7 +649,7 @@ if (isEnabled("ds-payload-type-hooks")) {
`post` model should be used:

```app/serializers/application.js
import DS from "ember-data";
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({
modelNameFromPayloadType(payloadType) {
Expand Down Expand Up @@ -701,11 +697,11 @@ if (isEnabled("ds-payload-type-hooks")) {
namespaces model name for the `post` should be used:

```app/serializers/application.js
import DS from "ember-data";
import DS from 'ember-data';

export default JSONAPISerializer.extend({
payloadTypeFromModelName(modelName) {
return "api::v1::" + modelName;
return 'api::v1::' + modelName;
}
});
```
Expand Down