mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Added hacky method for accessing meta
value of single-record requests
no issue - Ember Data does not support accessing meta data included in the response to single-record requests such as save/delete - approach to allow it taken from https://github.com/emberjs/data/pull/4077#issuecomment-200780097
This commit is contained in:
parent
f42f2a29a3
commit
7bb24df7b9
3 changed files with 25 additions and 2 deletions
12
ghost/admin/app/models/base.js
Normal file
12
ghost/admin/app/models/base.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Model from 'ember-data/model';
|
||||
|
||||
export default Model.extend({
|
||||
// this is a hack that gives us access to meta data in single resource responses
|
||||
// allows similar response.get('_meta') as with multi-resource responses but can
|
||||
// suffer from race conditions
|
||||
// TODO: review once the record links and meta RFC lands
|
||||
// https://github.com/emberjs/rfcs/blob/master/text/0332-ember-data-record-links-and-meta.md
|
||||
get _meta() {
|
||||
return this._internalModel.type.___meta;
|
||||
}
|
||||
});
|
|
@ -1,12 +1,13 @@
|
|||
/* eslint-disable camelcase */
|
||||
import Model, {attr, hasMany} from '@ember-data/model';
|
||||
import BaseModel from './base';
|
||||
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
||||
import {attr, hasMany} from '@ember-data/model';
|
||||
import {computed} from '@ember/object';
|
||||
import {equal, or} from '@ember/object/computed';
|
||||
import {inject as service} from '@ember/service';
|
||||
import {task} from 'ember-concurrency';
|
||||
|
||||
export default Model.extend(ValidationEngine, {
|
||||
export default BaseModel.extend(ValidationEngine, {
|
||||
validationType: 'user',
|
||||
|
||||
name: attr('string'),
|
||||
|
|
|
@ -3,6 +3,16 @@ import {camelize, decamelize, underscore} from '@ember/string';
|
|||
import {pluralize} from 'ember-inflector';
|
||||
|
||||
export default RESTSerializer.extend({
|
||||
// hacky method for getting access to meta data for single-resource responses
|
||||
// https://github.com/emberjs/data/pull/4077#issuecomment-200780097
|
||||
// TODO: review once the record links and meta RFC lands
|
||||
// https://github.com/emberjs/rfcs/blob/master/text/0332-ember-data-record-links-and-meta.md
|
||||
extractMeta(store, typeClass) {
|
||||
let meta = this._super(...arguments);
|
||||
typeClass.___meta = meta;
|
||||
return meta;
|
||||
},
|
||||
|
||||
serialize(/*snapshot, options*/) {
|
||||
let json = this._super(...arguments);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue