Closed denisnazarov closed 10 years ago
cc @stefanpenner
I am a little confused, the keyForRelationship
method just returns the argument, nothing else?
Hey @daliwali,
It should be more clear in this test: https://github.com/plyfe/ember-json-api/blob/convert-keys/tests/integration/serializer_test.js#L100-L106
One can choose to define keyForAttribute/keyForRelationship on the serializer to convert the camelized keys to snake_cased ones, for example to use with a Rails backend that expects snakecased.
This PR fixes serialization of belongsTo/hasMany, which previously wouldn't call keyForRelationship. This would result in part of the attributes being properly converted, and the ones that represent relationships would remain camelcased.
The PR is based on code in ActiveModelAdapter: https://github.com/emberjs/data/blob/master/packages/activemodel-adapter/lib/system/embedded_records_mixin.js#L146
keyForRelationship returns the argument as a default if you choose not to overrride keyForRelationship in your serializer, otherwise we would get function undefined if it wasn't implemented.
...ongsTo and serializeHasMany