I\'m working on an Ember app that is using Ember Data and the now default json-api adapter.
According to the json-api spec (http://jsonapi.org/format/#crud-deleting)
Ember does not support meta
for single model requests (find
,save
and destroyRecord
) at the moment!
If you want this you have to hook into ember internals.
The following code uses ember internals from ember 2.3 and may break in future versions!
There is the undocumented _metadataFor
function on the store
that gives you the last metadata for a given type. I use a custom initializer to always save it to the Model
:
import Ember from 'ember';
import DS from 'ember-data';
const {set} = Ember;
export function initialize(application) {
DS.Model.reopen({
meta: null,
didCommit() {
this._super(...arguments);
set(this, 'meta', this.store._metadataFor(this.constructor.modelName));
}
});
};
export default {
name: 'meta',
initialize: initialize
};
After this you can do model.save().then(() => console.log(model.get('meta')))
or model.destroyRecord.then(() => console.log(model.get('meta')))
.
Maybe checkout this ember-twiddle.