Skip to content
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

Merged
merged 1 commit into from
Feb 16, 2016

Conversation

groyoh
Copy link
Member

@groyoh groyoh commented Feb 13, 2016

Follow up to #1504 (comment). 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
# => { links: { posts: { related: { href: nil, meta: { id: 1 } }  } } }.

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.

@groyoh groyoh force-pushed the fix_relationship_href branch 2 times, most recently from a1d7bf9 to 37ce6e3 Compare February 13, 2016 13:47
@@ -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)
Copy link
Member

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.

?

Copy link
Member Author

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).
@groyoh groyoh force-pushed the fix_relationship_href branch from 37ce6e3 to 3cbc054 Compare February 15, 2016 08:27
@@ -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(',')
Copy link
Member Author

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.

@bf4
Copy link
Member

bf4 commented Feb 15, 2016

Looks good.

bf4 added a commit that referenced this pull request Feb 16, 2016
[FIX] bug displaying nil for relationship link href
@bf4 bf4 merged commit a6c6979 into rails-api:master Feb 16, 2016
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.

2 participants