Skip to content

Instantly share code, notes, and snippets.

@Leooo
Last active October 18, 2019 12:25
Show Gist options
  • Save Leooo/499e21ed033ff8270dcd966904b02c4c to your computer and use it in GitHub Desktop.
Save Leooo/499e21ed033ff8270dcd966904b02c4c to your computer and use it in GitHub Desktop.
model-fragments issue 340
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';
import MF from 'ember-data-model-fragments';
export default Model.extend({
changeTracker: {trackHasMany: true, auto: true, enableIsDirty: true},
telephoneNumber: MF.fragment('phone-type')
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
import MF from 'ember-data-model-fragments';
export default MF.Fragment.extend({
number: attr('string')
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
const store = this.get('store');
/*const appointment = store.createRecord('appointment', {});
const telephoneNumber = store.createFragment('phoneType',{
number: '07777777777'
});
appointment.set('telephoneNumber', telephoneNumber);*/
store.push({
data: [{
id: 1,
type: 'appointment',
attributes: {
telephoneNumber: {
number: '07777777777'
}
}
}]
});
const appointment = this.store.peekRecord('appointment', 1);
appointment.saveTrackerChanges();
window.appointment = appointment;
appointment.set('telephoneNumber.number', '07123456789');
console.log('changedAttributes: ', appointment.changedAttributes());
appointment.saveTrackerChanges();
appointment.set('telephoneNumber.number', '07123456700');
console.log('changedAttributes 2: ', appointment.changedAttributes());
debugger;
return appointment
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.8",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.5.2",
"ember-data-model-fragments": "4.0.0",
"ember-data-change-tracker" : "0.8.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment