Last active
October 30, 2017 21:22
-
-
Save danielspaniel/df81a058c787d97db31366f939a01591 to your computer and use it in GitHub Desktop.
Push Polymorphic
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({ | |
appName: 'Ember Twiddle' | |
}); |
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 Hat from "./hat"; | |
export default Hat.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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo } from "ember-data/relationships"; | |
export default Model.extend({ | |
type: attr('string'), | |
person: belongsTo('person',{async: false, inverse: 'hats'}) | |
}); |
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 { hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
hats: hasMany('hat', { async: false, polymorphic: true }), | |
}); |
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 Hat from "./hat"; | |
export default Hat.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 Ember from 'ember'; | |
import DS from 'ember-data'; | |
const { $ } = Ember; | |
const personData = { | |
data: { | |
id: 1, | |
type: 'person', | |
attributes: {} | |
} | |
}; | |
const hatData = { | |
data: { | |
relationships: { | |
person: { | |
data: { id:1, type: 'person' } | |
} | |
} | |
} | |
}; | |
const bigHatData1 = $.extend(true, {}, hatData, {data: {id:1, type:'big-hat'}}); | |
const bigHatData2 = $.extend(true, {}, hatData, {data: {id:2, type:'big-hat'}}); | |
const smallHatData1 = $.extend(true, {}, hatData, {data: {id:1, type:'small-hat'}}); | |
const smallHatData2 = $.extend(true, {}, hatData, {data: {id:2, type:'small-hat'}}); | |
const smallHatData3 = $.extend(true, {}, hatData, {data: {id:3, type:'small-hat'}}); | |
export default Ember.Route.extend({ | |
model() { | |
let person = this.store.push(personData); | |
// works with created .. but not pushed records | |
// if you even create ONE new record it all works fine | |
// this.store.createRecord('big-hat', {person}); | |
// this.store.createRecord('small-hat', {person}); | |
this.store.push(bigHatData1); | |
this.store.push(smallHatData1); | |
this.store.push(bigHatData2); | |
this.store.push(smallHatData2); | |
return person; | |
}, | |
setupController(controller, person) { | |
controller.setProperties({ | |
person, | |
pushedHats: person.get('hats').toArray(), | |
// in twiddle.json switch to ember-data: "2.13" to see it working | |
DS | |
}); | |
} | |
}); |
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.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.14.7" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment