Created
June 1, 2016 21:30
-
-
Save dfreeman/f4115a726ae0e55e997826d7e151d54e to your computer and use it in GitHub Desktop.
Embedded Playground
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 Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| serialized: Ember.computed('model', function() { | |
| const serialized = this.get('model').serialize({ includeId: true }); | |
| return JSON.stringify(serialized, null, 2); | |
| }) | |
| }); |
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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| name: attr('string') | |
| }); |
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 Model from "ember-data/model"; | |
| import attr from "ember-data/attr"; | |
| import { belongsTo, hasMany } from "ember-data/relationships"; | |
| export default Model.extend({ | |
| embeddees: hasMany('embeddee') | |
| }); |
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 Ember from 'ember'; | |
| export default Ember.Route.extend({ | |
| beforeModel() { | |
| const first = this.store.createRecord('embeddee', { id: 1, name: 'one' }); | |
| const second = this.store.createRecord('embeddee', { id: 2, name: 'two' }); | |
| this.store.createRecord('embedder', { id: 'asdf', embeddees: [first, second] }); | |
| }, | |
| model() { | |
| return this.store.peekAll('embedder').get('firstObject'); | |
| } | |
| }); |
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 RESTSerializer from 'ember-data/serializers/rest'; | |
| export default RESTSerializer.extend({}); |
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 RESTSerializer from 'ember-data/serializers/rest'; | |
| import EmbeddedRecordsMixin from 'ember-data/mixins/embedded-records'; | |
| export default RESTSerializer.extend(EmbeddedRecordsMixin, { | |
| attrs: { | |
| embeddees: { serialize: 'records' } | |
| } | |
| }); |
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
| { | |
| "version": "0.8.1", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.5.1", | |
| "ember-data": "2.5.2", | |
| "ember-template-compiler": "2.5.1" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment