In our application, we're using ember data with JSON API on the client side, Rails API with Active Model Serializers on the server side.
ActiveModelSerializers, by default, give us attributes in underscored form, so we had to override our application serializer like so:
import Ember from 'ember';
import DS from 'ember-data';
var underscore = Ember.String.underscore;
export default DS.JSONAPISerializer.extend({
keyForAttribute: function(attr) {
return underscore(attr); // needed to transform AMS's underscores
},
keyForRelationship: function(rawKey) {
return underscore(rawKey); // needed to transform AMS's underscores
}
});
However, when we define a factory, we have to use camelized properties:
FactoryGuy.define('user', {
default: {
admin: false,
canTrial: false,
email: 'johndoe@gmail.com',
fullName: 'John Doe',
id: 1
}
});
From debugging, I'm seeing that what factory guy does is the following:
- Get the factory
- Run it through the default JSON API serializer to get a dasherized form
- Pass it on to the store as an adapter payload
- The store then uses the actual application serializer (our custom one), to convert back to the client camelized form.
- Since the adapter expects an underscored form as input, the multi-word properties simply get ignored.
We could modify our adapter to account for this behavior and simply support both underscored and dasherized form of attribute keys, but I'm thinking FactoryGuy should use the application serializer anyway. Otherwise, it would prevent us from customizing the way our attribute (or relationship) keys are named.
Am I missing something, or is this really what's going on here?
In our application, we're using ember data with JSON API on the client side, Rails API with Active Model Serializers on the server side.
ActiveModelSerializers, by default, give us attributes in underscored form, so we had to override our application serializer like so:
However, when we define a factory, we have to use camelized properties:
From debugging, I'm seeing that what factory guy does is the following:
We could modify our adapter to account for this behavior and simply support both underscored and dasherized form of attribute keys, but I'm thinking FactoryGuy should use the application serializer anyway. Otherwise, it would prevent us from customizing the way our attribute (or relationship) keys are named.
Am I missing something, or is this really what's going on here?