mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 21:41:49 +03:00
Fixed Ember Data deprecation warnings for queryRecord
response returning array
no issue - our API always returns an array whether we're performing a browse or find request but Ember Data expects explicit find requests to return a single object and throws deprecations when it sees an array - https://deprecations.emberjs.com/ember-data/v2.x/#toc_store-queryrecord-array-response-with-restserializer - we previously had `normalizeSingleResponse` overrides in specific models that we use with `queryRecord` but we've since introduced `queryRecord` usage on more models but the associated "fix" was not duplicated in the serializers for those models leading to many deprecation warnings logged to the console in development and when testing - moved the fix to the application serializer so it applies to all models - explicitly excluded `setting` model because that's a special-case and has it's own array-into-object serialization to represent multiple settings records as a single model instance
This commit is contained in:
parent
1e4af5d072
commit
9a24be2b4f
@ -49,4 +49,16 @@ export default class Application extends RESTSerializer {
|
||||
|
||||
return transform(key);
|
||||
}
|
||||
|
||||
normalizeQueryRecordResponse(store, primaryModelClass, payload) {
|
||||
const root = this.keyForAttribute(primaryModelClass.modelName);
|
||||
const pluralizedRoot = pluralize(root);
|
||||
|
||||
if (payload[pluralizedRoot] && root !== 'setting') {
|
||||
payload[root] = payload[pluralizedRoot][0];
|
||||
delete payload[pluralizedRoot];
|
||||
}
|
||||
|
||||
return super.normalizeQueryRecordResponse(...arguments);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
||||
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
||||
import {pluralize} from 'ember-inflector';
|
||||
|
||||
export default class PostSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
||||
// settings for the EmbeddedRecordsMixin.
|
||||
@ -14,22 +13,6 @@ export default class PostSerializer extends ApplicationSerializer.extend(Embedde
|
||||
email: {embedded: 'always'}
|
||||
};
|
||||
|
||||
normalizeSingleResponse(store, primaryModelClass, payload) {
|
||||
let root = this.keyForAttribute(primaryModelClass.modelName);
|
||||
let pluralizedRoot = pluralize(primaryModelClass.modelName);
|
||||
|
||||
if (payload[pluralizedRoot]) {
|
||||
payload[root] = payload[pluralizedRoot][0];
|
||||
delete payload[pluralizedRoot];
|
||||
}
|
||||
|
||||
return super.normalizeSingleResponse(...arguments);
|
||||
}
|
||||
|
||||
normalizeArrayResponse() {
|
||||
return super.normalizeArrayResponse(...arguments);
|
||||
}
|
||||
|
||||
serialize(/*snapshot, options*/) {
|
||||
let json = super.serialize(...arguments);
|
||||
|
||||
|
@ -19,16 +19,4 @@ export default class UserSerializer extends ApplicationSerializer.extend(Embedde
|
||||
|
||||
return super.extractSingle(...arguments);
|
||||
}
|
||||
|
||||
normalizeSingleResponse(store, primaryModelClass, payload) {
|
||||
let root = this.keyForAttribute(primaryModelClass.modelName);
|
||||
let pluralizedRoot = pluralize(primaryModelClass.modelName);
|
||||
|
||||
if (payload[pluralizedRoot]) {
|
||||
payload[root] = payload[pluralizedRoot][0];
|
||||
delete payload[pluralizedRoot];
|
||||
}
|
||||
|
||||
return super.normalizeSingleResponse(...arguments);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user