Last active
March 18, 2017 02:45
-
-
Save danielspaniel/5fa2844404c7f9bc3ecba0e6ed79c605 to your computer and use it in GitHub Desktop.
polymorphic belongTo
This file contains 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 DS from 'ember-data'; | |
export default DS.RESTAdapter.extend({ | |
}); |
This file contains 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 Twiddles', | |
thingIds: Ember.computed.mapBy('model.things', 'id'), | |
thingState: Ember.computed.mapBy('model.things', 'isDeleted') | |
}); |
This file contains 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
<script src="https://cdn.jsdelivr.net/jquery.mockjax/2.2.1/jquery.mockjax.min.js" type="text/javascript"></script> |
This file contains 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 Person from "./person"; | |
import attr from "ember-data/attr"; | |
export default Person.extend({ | |
type: attr('string', { defaultValue: 'BigPerson' }) | |
}); |
This file contains 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, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
type: attr('string'), | |
things: hasMany('thing') | |
}); |
This file contains 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, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
person: belongsTo('person', {polymorphic: true}) | |
}); |
This file contains 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.Route.extend({ | |
beforeModel() { | |
let data = { | |
data: { | |
id: 1, | |
type: 'big-person', | |
relationships: { | |
things: { | |
data: [ | |
] | |
} | |
} | |
}, | |
included: [ | |
//{id: 1, type: "thing"}, | |
//{id: 2, type: "thing"} | |
] | |
}; | |
this.store.pushPayload(data); | |
}, | |
model() { | |
let person = this.store.peekRecord('person', 1); | |
$.mockjax({ | |
url: '/things', | |
type: 'POST', | |
responseText: {thing: {id: 1, person: {type: 'big-person', id: 1}}} | |
}); | |
let thing = this.store.createRecord('thing', {person: person}); | |
thing.save() | |
return thing; | |
} | |
}); |
This file contains 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.11.0", | |
"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": "release", | |
"ember-data": "release", | |
"ember-template-compiler": "release", | |
"ember-testing": "release" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment