From 311cd15c2ddc7818e83ccde3ab8c20e66cea6c39 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 13 Sep 2019 14:46:25 +0200 Subject: [PATCH] disable static includes checks when using polymorphic relations --- lib/fast_jsonapi/object_serializer.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fast_jsonapi/object_serializer.rb b/lib/fast_jsonapi/object_serializer.rb index 1996a7d6..15954e7e 100644 --- a/lib/fast_jsonapi/object_serializer.rb +++ b/lib/fast_jsonapi/object_serializer.rb @@ -304,7 +304,12 @@ def validate_includes!(includes) relationships_to_serialize = klass.relationships_to_serialize || {} relationship_to_include = relationships_to_serialize[parsed_include] raise ArgumentError, "#{parsed_include} is not specified as a relationship on #{klass.name}" unless relationship_to_include - klass = relationship_to_include.serializer.to_s.constantize unless relationship_to_include.polymorphic.is_a?(Hash) + if relationship_to_include.polymorphic.is_a?(Hash) + # static check is not possible since the serializer is defined based on the instance class + return + else + klass = relationship_to_include.serializer.to_s.constantize + end end end end