Created
March 2, 2018 23:30
-
-
Save bendemboski/a54092c7ba5fc2debd7ee33ff01e75b8 to your computer and use it in GitHub Desktop.
Relationship Cache
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 Twiddle' | |
}); |
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 LibraryOwner from "./libraryowner"; | |
import { belongsTo } from "ember-data/relationships"; | |
export default LibraryOwner.extend({ | |
main: belongsTo('library'), | |
science: belongsTo('library') | |
}); |
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 } from "ember-data/relationships"; | |
export default Model.extend({ | |
owner: belongsTo('libraryowner', { polymorphic: true }), | |
ownerType: attr('string'), | |
ownerId: attr('string'), | |
name: attr('string') | |
}); |
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"; | |
export default Model.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'; | |
const { RSVP: { hash } } = Ember; | |
const library1Data = { | |
data: { | |
id: 1, | |
type: 'library', | |
attributes: { | |
name: 'Main branch' | |
}, | |
relationships: { | |
data: { id: 1, type: 'city' } | |
} | |
} | |
}; | |
const library2Data = { | |
data: { | |
id: 2, | |
type: 'library', | |
attributes: { | |
name: 'Science branch' | |
}, | |
relationships: { | |
data: { id: 1, type: 'city' } | |
} | |
} | |
}; | |
const cityData = { | |
data: { | |
id: 1, | |
type: 'city', | |
attributes: {}, | |
relationships: { | |
main: { | |
data: { id: 1, type: 'library' } | |
}, | |
science: { | |
data: { id: 2, type: 'library' } | |
} | |
} | |
} | |
}; | |
export default Ember.Route.extend({ | |
model() { | |
this.store.push(library1Data); | |
this.store.push(library2Data); | |
this.store.push(cityData); | |
this.store.unloadAll('library'); | |
this.store.unloadAll('city'); | |
this.store.push(library1Data); | |
this.store.push(library2Data); | |
let city = this.store.push(cityData); | |
return hash({ | |
city, | |
main: city.get('main'), | |
science: city.get('science') | |
}); | |
} | |
}); |
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.13.0", | |
"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-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.18.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment