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

Remove nil relationships links #1833

Merged
merged 1 commit into from
Jul 12, 2016
Merged

Conversation

groyoh
Copy link
Member

@groyoh groyoh commented Jul 7, 2016

Purpose

Given this serializer:

class PostSerializer < ActiveModel::Serializer
  has_one :author do
    link :related do
      "www.example.com/author/#{object.id}" if false # the conditional is set to false to demonstrate the issue
    end
  end
end

Expected behavior

{
  "data": {
    "type": "post",
    "id": "1",
    "relationships": {
      "author": {
        "data": { "id": 1, "type": "author" }
      }
    }
  }
}

Actual behavior

{
  "data": {
    "type": "post",
    "id": "1",
    "relationships": {
      "author": {
        "data": { "id": 1, "type": "author" },
        "links": {
          "related": null
        }
      }
    }
  }
}

Changes

The nil links are now removed. This is similar as to how resource links are handled right now.

@cgmckeever
Copy link
Contributor

nice!

@groyoh groyoh added the S: Bug label Jul 7, 2016
@bf4
Copy link
Member

bf4 commented Jul 8, 2016

@groyoh LGTM, ok to merge

@NullVoxPopuli
Copy link
Contributor

I'm good with this.

@groyoh groyoh force-pushed the bugfix/nil-link branch from 345d5be to a5c95d0 Compare July 12, 2016 11:23
@groyoh groyoh force-pushed the bugfix/nil-link branch from a5c95d0 to 0f53e6c Compare July 12, 2016 11:23
@groyoh groyoh merged commit 9a206a1 into rails-api:master Jul 12, 2016
@groyoh groyoh deleted the bugfix/nil-link branch July 12, 2016 12:02
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