Skip to content

Instantly share code, notes, and snippets.

@alexspeller
Last active November 16, 2018 19:05
Show Gist options
  • Save alexspeller/4816e60591e3c2e156f820ccf0114ea3 to your computer and use it in GitHub Desktop.
Save alexspeller/4816e60591e3c2e156f820ccf0114ea3 to your computer and use it in GitHub Desktop.
New Twiddle
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
user: belongsTo(),
balance: attr('number')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
accounts: hasMany(),
name: attr('string')
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
this.store.pushPayload({
data: {
type: "users",
id: 1,
attributes: {
name: 'Alex'
}
}
});
this.store.pushPayload({
data: {
type: "accounts",
id: 1,
relationships: {
user: {
data: {
id: '1',
type: 'users'
}
}
},
attributes: {
balance: 123
}
}
});
return this.store.peekRecord('user', 1);
}
});
<h1>Name: {{model.name}}</h1>
<h2>Accounts: {{model.accounts.length}}</h2>
<dl>
{{#each model.accounts as |account|}}
<dt>ID: {{account.id}}</dt>
<dd>balance: {{account.balance}}</dd>
{{account.user}}
{{/each}}
</dl>
{
"version": "0.9.2",
"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.16.2",
"ember-data": "2.16.4",
"ember-template-compiler": "2.16.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment