-
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
Fix bug displaying nil for relationship link href #1516
Conversation
a1d7bf9
to
37ce6e3
Compare
@@ -14,6 +14,8 @@ Features: | |||
- [#1340](https://github.com/rails-api/active_model_serializers/pull/1340) Add support for resource-level meta. (@beauby) | |||
|
|||
Fixes: | |||
- [#1516](https://github.com/rails-api/active_model_serializers/pull/1501) Using only meta for relationship links would result | |||
in a `nil` href. (@groyoh) |
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.
No longer return a
nil
href when only adding meta to a relationship link.
?
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.
Fixed it ;)
When using the relationship link with a block, calling "meta" without "href", e.g. has_one :bio do link :related do meta id: 1 end end results in in a nil "href", e.g. { links: { posts: { related: { href: nil, meta: { id: 1 } } } } }. According to JSONAPI, we should be able to use meta without href (http://jsonapi.org/format/#document-links).
37ce6e3
to
3cbc054
Compare
@@ -19,19 +19,25 @@ class RelationshipAuthorSerializer < ActiveModel::Serializer | |||
|
|||
has_many :locations do | |||
link :related do | |||
ids = object.locations.map!(&:id).join(',') | |||
ids = object.locations.map(&:id).join(',') |
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 was using map!
instead of map
with actually change the array and might cause some issues.
Looks good. |
[FIX] bug displaying nil for relationship link href
Follow up to #1504 (comment). When using the relationship link with a block, calling "meta" without "href", e.g.
results in in a nil "href".
According to JSONAPI, we should be able to use meta without href (http://jsonapi.org/format/#document-links).
Depending on the ouput from #1514, this PR might need some follow up.