Created
April 2, 2018 17:26
-
-
Save timrwood/e3279bc44fab6a3e63673fe06b2bfa0d to your computer and use it in GitHub Desktop.
Ember Data meta relationship
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', | |
parents: null, | |
actions: { | |
clear() { | |
this.store.unloadAll('parent'); | |
this.store.unloadAll('child'); | |
this.set('model', null); | |
}, | |
loadParent() { | |
this.store.pushPayload({ | |
data: { | |
id: 1, | |
type: 'parent', | |
relationships: { | |
children: { | |
data: [ | |
{ id: 1, type: 'child' }, | |
{ id: 2, type: 'child' } | |
] | |
} | |
} | |
}, | |
included: [ | |
{ id: 1, type: 'child' }, | |
{ id: 2, type: 'child' } | |
] | |
}); | |
console.log('loadParent') | |
this.set('model', this.store.peekAll('parent')); | |
}, | |
loadMeta() { | |
this.store.pushPayload({ | |
data: { | |
id: 1, | |
type: 'parent', | |
relationships: { | |
children: { | |
meta: { included: false } | |
} | |
} | |
} | |
}); | |
console.log('loadMeta') | |
this.set('model', this.store.peekAll('parent')); | |
} | |
} | |
}); |
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, hasMany } from 'ember-data/relationships'; | |
export default Model.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, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
children: hasMany('child') | |
}); |
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 DS from 'ember-data' | |
export default DS.JSONAPISerializer.extend({ | |
extractRelationships(modelClass, resourceHash) { | |
let relationships = this._super(modelClass, resourceHash) | |
console.log(relationships) | |
return relationships | |
}, | |
}) |
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.13.1", | |
"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.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment