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

Make linked resource type names consistent with root names #771

Merged
merged 2 commits into from
Jan 11, 2015

Conversation

pittst3r
Copy link
Contributor

Using the JSON API adapter, when models are coming from a Rails engine and are namespaced, the namespace was reflected in linked resource types but not in the root type, leading to inconsistent resource names. This PR removes the namespace from linked resources. For example:

Given models like this:

module Pizza

  class Dough < ActiveRecord::Base
    belongs_to :pie
  end

  class Pie < ActiveRecord::Base
    has_one :crust, class_name: 'Pizza::Dough'
  end

end

Serialization could end up looking like this:

{
  linked: {
    'pizza/doughs': [{
      id: 456
    }]
  },
  pies: {
    id: 123,
    links: {
      crust: {
        id: 456,
        type: 'pizza/dough'
      }
    }
  }
}

But should look like this:

{
  linked: {
    'doughs': [{
      id: 456
    }]
  },
  pies: {
    id: 123,
    links: {
      crust: {
        id: 456,
        type: 'dough'
      }
    }
  }
}

@guilleiguaran
Copy link
Member

can we have a test for this to avoid regressions in the future?

@pittst3r
Copy link
Contributor Author

Indeed, incoming.

@pittst3r
Copy link
Contributor Author

@guilleiguaran How's this look?

@guilleiguaran
Copy link
Member

Looks great for me 👍

guilleiguaran added a commit that referenced this pull request Jan 11, 2015
Make linked resource type names consistent with root names
@guilleiguaran guilleiguaran merged commit 7085afe into rails-api:master Jan 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants