1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

Fixed serialisation of belongsTo relationships

no issue
- `belongsTo` relationships were failing to save on the server correctly because they did not contain the `_id` suffix
  - became noticeable when the first standalone `belongsTo` relationship was added to webhooks
  - added conditional for special-case `_by` relationships which don't require an additional `_id` when saving to the API
This commit is contained in:
Kevin Ansfield 2018-10-18 18:23:19 +01:00
parent 756065d0fe
commit edc36c0a55

View file

@ -1,5 +1,5 @@
import RESTSerializer from 'ember-data/serializers/rest';
import {decamelize} from '@ember/string';
import {camelize, decamelize, underscore} from '@ember/string';
import {pluralize} from 'ember-inflector';
export default RESTSerializer.extend({
@ -27,5 +27,16 @@ export default RESTSerializer.extend({
keyForAttribute(attr) {
return decamelize(attr);
},
keyForRelationship(key, typeClass, method) {
let transform = method === 'serialize' ? underscore : camelize;
if (typeClass === 'belongsTo' && !key.match(/(Id|By)$/)) {
let transformed = `${transform(key)}_id`;
return transformed;
}
return transform(key);
}
});