Skip to content

Fix caching for namespaced polymorphic associations#1080

Closed
alachaum wants to merge 1 commit intoJSONAPI-Resources:masterfrom
alachaum:fix-caching-namespaced-res
Closed

Fix caching for namespaced polymorphic associations#1080
alachaum wants to merge 1 commit intoJSONAPI-Resources:masterfrom
alachaum:fix-caching-namespaced-res

Conversation

@alachaum
Copy link

@alachaum alachaum commented Jul 1, 2017

Hi guys,

I noticed there was an issue with caching when looking up namespaced resource classes for polymorphic associations. This issue prevents include queries on resources having a polymorphic association.

Something like this:

class Api::V1::PictureResource < JSONAPI::Resource
  caching
  has_one :imageable, polymorphic: true
end

class Api::V1::ProductResource < JSONAPI::Resource
  has_one :picture
end

..will fail when doing:

# Fails because JR attempts to lookup PictureResource when compiling cached fragments
GET /api/v1/pictures?include=imageable

The test attached to this PR does not create a 500 if the patch is not applied (because both PictureResource and Api::V1::PictureResource are defined) but clearly show that the links are incorrect when caching is enabled.

@lgebhardt
Copy link
Contributor

@alachaum I think this has been fixed with the rework that has happened in #1045. Please check it out and reopen this if it's still a problem. We'll need to fix it another way since the to_real_resource method no longer exists.

@lgebhardt lgebhardt closed this Sep 1, 2017
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.

2 participants