Skip to content

update integration documentation for ember and JSONAPI to include… - #1802

Merged
bf4 merged 2 commits into
rails-api:masterfrom
kyleshevlin:update_integrations_ember_and_json_api
Jun 27, 2016
Merged

update integration documentation for ember and JSONAPI to include…#1802
bf4 merged 2 commits into
rails-api:masterfrom
kyleshevlin:update_integrations_ember_and_json_api

Conversation

@kyleshevlin

@kyleshevlin kyleshevlin commented Jun 14, 2016

Copy link
Copy Markdown
Contributor

…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.

…_transform underscores to match the attribute and relationship underscore transformations
Comment thread docs/integrations/ember-and-json-api.md Outdated
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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@NullVoxPopuli NullVoxPopuli Jun 14, 2016

Copy link
Copy Markdown
Contributor

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_transformto`: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
.

Copy link
Copy Markdown
Contributor Author

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

@NullVoxPopuli

Copy link
Copy Markdown
Contributor

LGTM

)

Mime::Type.unregister :json
Mime::Type.register 'application/json', :json, api_mime_types

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bf4
bf4 merged commit c029c00 into rails-api:master Jun 27, 2016
@kyleshevlin
kyleshevlin deleted the update_integrations_ember_and_json_api branch June 27, 2016 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants