Skip to content

Instantly share code, notes, and snippets.

@mukk85
Last active August 5, 2021 21:43
Show Gist options
  • Save mukk85/caf9f27bcd73801bb5c6aa09ae100f53 to your computer and use it in GitHub Desktop.
Save mukk85/caf9f27bcd73801bb5c6aa09ae100f53 to your computer and use it in GitHub Desktop.
New Twiddle
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
parentChildCount = 0;
parentChildCountAfter = 0;
@service store;
constructor(owner) {
super(owner);
const parent = this.store.createRecord('parent', {
name: 'Parent'
});
const child1 = this.store.createRecord('child', {
parent: parent,
name: 'Child 1',
});
const child2 = this.store.createRecord('child', {
parent: parent,
name: 'Child 1',
});
const child3 = this.store.createRecord('child', {
parent: parent,
name: 'Child 1',
});
this.parentChildCount = parent.children.length;
const child4 = this.store.createRecord('child', {
name: 'Child 1',
});
child4.parent = parent;
child4.save();
this.parentChildCountAfter = parent.children.length;
}
}
import Model from 'ember-data/model';
import { belongsTo } from 'ember-data/relationships';
import attr from 'ember-data/attr';
export default class extends Model {
@attr('string') name;
@belongsTo('parent') parent;
}
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
export default class extends Model {
@attr('string') name;
@hasMany('child') children;
}
<h1>Welcome to {{this.appName}}</h1>
<br>
Parent Child Count: {{this.parentChildCount}}
After Save: {{this.parentChildCountAfter}}
<br>
{{outlet}}
<br>
<br>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-data": "3.18.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment