Skip to content

Instantly share code, notes, and snippets.

@GCorbel
Last active October 21, 2018 16:27
Show Gist options
  • Save GCorbel/fb89af5cd10fdfa0ee1eb2392d7ef923 to your computer and use it in GitHub Desktop.
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.
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
}
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
}
{
"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"
}
}
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