Skip to content

Instantly share code, notes, and snippets.

@pangratz
Forked from blatyo/controllers.application.js
Created August 5, 2016 19:02
Show Gist options
  • Save pangratz/183295aa50273417122307f758c73f03 to your computer and use it in GitHub Desktop.
Save pangratz/183295aa50273417122307f758c73f03 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
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')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
text: attr('string')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
author: belongsTo('author'),
comments: hasMany('comment')
});
import Ember from 'ember';
export default Ember.Route.extend({
model(){
this.store.pushPayload('post', {
data: {
id: 1,
type: 'post',
relationships: {
author: {data: {id: 1, type: 'author'}},
comments: { data:[{id: 1, type: 'comment'}, {id: 2, type: 'comment'}] }
}
},
included: [
{id: 1, type: 'author', attributes: {name: "joe"}},
{id: 1, type: 'comment', attributes: {text: "blah"}},
{id: 2, type: 'comment', attributes: {text: "blah"}}
]
})
return this.store.peekAll('post').get('firstObject')
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
{{model.author.name}}
{{#each model.comments as |comment|}}
{{comment.text}}
{{/each}}
<br>
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment