-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update integration documentation for ember and JSONAPI to include… #1802
update integration documentation for ember and JSONAPI to include… #1802
Conversation
…_transform underscores to match the attribute and relationship underscore transformations
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi | ||
``` | ||
|
||
You will also want to set the `key_transform` to `:underscore` since you will adjust the attributes in your Ember serializer to use underscores instead of dashes later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There actually isn't a reason to do this anymore, since ember accepts our default key transform without modification. It's still worth mentioning to make sure both server and client side apps have manching key transforms though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say the bigger point here is that if you'd like to handle key transform on the client (Ember) side, to use key_transform: :unaltered
since it's much faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very knowledgeable on this gem, and perhaps there is an actual issue here and I'm happy to raise it if someone can help me discover it, but you are correct that Ember accepts payloads from AMS correctly, as setting the adapter correctly dashes names on outgoing payloads; however, it fails on incoming payloads with dashes. I could not get a PATCH to update attributes that were dasherized instead of underscored.
Thus, when someone referred me to this integration and it works once I adjust the key_transform to underscore, it seemed like submitting a PR to update the docs was the right thing to do.
As is, in theory, you shouldn't need to update keyForAttribute or keyForRelationship in Ember since they are dasherized, and you shouldn't need a key_transform change in AMS since it's default for :json_api
is :dash
;
If you plan to keep this integration here with the recommendation to underscore Ember's keys, than the keys also need to be transformed in AMS to the best of my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at my aeonvera repository, you'll see how to handle dashed
attributes on patch. I think about every controller does the same technique.
But yes, the overall guide should be updated to show how to handle dashed
everything.
That said, having the underscore option is handy if key transform
performance is a concern, so I'd still like to keep notes on how to use
underscored attributes everywhere. 😉
On Tue, Jun 14, 2016, 11:04 AM Kyle Shevlin notifications@github.com
wrote:
In docs/integrations/ember-and-json-api.md
#1802 (comment)
:-there are multiple mimetypes for json that should all be parsed similarly, so
+First, set the adapter type in an initializer file:
+
+ruby +# config/initializers/ams_config.rb +ActiveModelSerializers.config.adapter = :json_api +
+
+or:
+
+```ruby
+# config/initializers/ams_config.rb
+ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::JsonApi
+```
+
+You will also want to set thekey_transform
to`:underscore` since you will adjust the attributes in your Ember serializer to use underscores instead of dashes later.I am not very knowledgeable on this gem, and perhaps there is an actual
issue here and I'm happy to raise it if someone can help me discover it,
but you are correct that Ember accepts payloads from AMS correctly, as
setting the adapter correctly dashes names on outgoing payloads; however,
it fails on incoming payloads with dashes. I could not get a PATCH to
update attributes that were dasherized instead of underscored.Thus, when someone referred me to this integration and it works once I
adjust the key_transform to underscore, it seemed like submitting a PR to
update the docs was the right thing to do.As is, in theory, you shouldn't need to update keyForAttribute or
keyForRelationship in Ember since they are dasherized, and you shouldn't
need a key_transform change in AMS since it's default for :json_api is
:dash;If you plan to keep this integration here with the recommendation to
underscore Ember's keys, than the keys also need to be transformed in AMS
to the best of my understanding.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rails-api/active_model_serializers/pull/1802/files/8df5b045f270ce502a0bd9f203c80ec5be64177e#r66988562,
or mute the thread
https://github.com/notifications/unsubscribe/AAMJasZCrtTZNwpEJJy5PBVqKhJm8Okfks5qLsLAgaJpZM4I0_G7
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made an update using :unaltered
and requiring the JSON API renderer file
LGTM |
) | ||
|
||
Mime::Type.unregister :json | ||
Mime::Type.register 'application/json', :json, api_mime_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…key_transform unaltered to match the attribute and relationship underscore transformations.
Purpose
Add missing info in integration documentation. If Ember serializers use underscores, key_transform needs to be set to unaltered.
Changes
Documentation is updated.
Caveats
None.