mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
0bfe99af72
Closes #3325 - Add Roles model and add hasMany roles to User model. - Add EmbeddedRelationAdapter that will automatically include hasMany relations in calls to the API. - UserAdapter and PostAdapter now extend EmbeddedRelationAdapter and all explicit includes from store.find() have been removed.
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import ApplicationSerializer from 'ghost/serializers/application';
|
|
|
|
var UserSerializer = ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
|
|
attrs: {
|
|
roles: { embedded: 'always' }
|
|
},
|
|
|
|
extractSingle: function (store, primaryType, payload) {
|
|
var root = this.keyForAttribute(primaryType.typeKey),
|
|
pluralizedRoot = Ember.String.pluralize(primaryType.typeKey);
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
delete payload[pluralizedRoot];
|
|
|
|
return this._super.apply(this, arguments);
|
|
},
|
|
|
|
keyForAttribute: function (attr) {
|
|
return attr;
|
|
},
|
|
|
|
keyForRelationship: function (relationshipName) {
|
|
// this is a hack to prevent Ember-Data from deleting our `tags` reference.
|
|
// ref: https://github.com/emberjs/data/issues/2051
|
|
// @TODO: remove this once the situation becomes clearer what to do.
|
|
if (relationshipName === 'roles') {
|
|
return 'role';
|
|
}
|
|
|
|
return relationshipName;
|
|
}
|
|
});
|
|
|
|
export default UserSerializer;
|