Last active
October 21, 2018 16:27
-
-
Save GCorbel/fb89af5cd10fdfa0ee1eb2392d7ef923 to your computer and use it in GitHub Desktop.
A form has many fields. Association are include in data.fields instead of data.included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
import { computed } from '@ember-decorators/object'; | |
import { attr, belongsTo } from '@ember-decorators/data'; | |
export default class Field extends DS.Model { | |
@belongsTo('form', { async: false }) form | |
@attr controlType | |
@attr label | |
@attr placeholder | |
@attr values | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
import { hasMany, attr } from '@ember-decorators/data'; | |
export default class Form extends DS.Model { | |
@hasMany('fields', { async: false }) fields | |
@attr() updatedAt | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data":{ | |
"attributes":{ | |
"updated-at":"2018-10-20T23:08:28.657Z" | |
}, | |
"fields":[ | |
{"data":{"id":"1","attributes":{"control-type":"text","label":"1","placeholder":"1","values":"1"},"relationships":{"form":{"data":{"type":"forms","id":"1"}}},"type":"fields"}} | |
], | |
"type":"forms" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.JSONAPISerializer.extend(DS.EmbeddedRecordsMixin , { | |
attrs: { | |
fields: { embedded: 'always' } | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment