Skip to content

Polymorphic relations do not work with fragment caching #889

@DuaneCompton

Description

@DuaneCompton

A simple polymorphic relationship like:
class Api::V1::TagResource < BaseResource belongs_to taggable, polymorphic: true end
and a call like /api/v1/tags/1?include=taggable

will fail on any of the .joins(:ar_hash) i.e.
https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource.rb#L1143
with the message:
Can not eagerly load the polymorphic association :taggable

Any ideas on how to avoid this. It seems like trying to not cache the polymorphic relations for now might be the best approach. However, this code appears to get hit regardless of if a resource is marked as cached or not. Which means that for simpler relations caching can not be enabled if any requests involve a poly. Any help would be appreciated. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions