From 21dd5b61e71bb87a662b813e7363dd908e7c4c16 Mon Sep 17 00:00:00 2001 From: Denis Talakevich Date: Fri, 17 Nov 2017 12:30:26 +0200 Subject: [PATCH] Processor#show_related_resources should pass options to result if they are calculated --- lib/jsonapi/processor.rb | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/jsonapi/processor.rb b/lib/jsonapi/processor.rb index 20a4265fa..0c0c906a0 100644 --- a/lib/jsonapi/processor.rb +++ b/lib/jsonapi/processor.rb @@ -186,32 +186,28 @@ def show_related_resources serializer, find_options) + opts = result_options if ((JSONAPI.configuration.top_level_meta_include_record_count) || (paginator && paginator.class.requires_record_count) || (JSONAPI.configuration.top_level_meta_include_page_count)) - record_count = source_resource.class.count_related( + opts[:record_count] = source_resource.class.count_related( source_resource.identity, relationship_type, find_options) end - if (JSONAPI.configuration.top_level_meta_include_page_count && record_count) - page_count = paginator.calculate_page_count(record_count) + if (JSONAPI.configuration.top_level_meta_include_page_count && opts[:record_count]) + opts[:page_count] = paginator.calculate_page_count(opts[:record_count]) end - pagination_params = if paginator && JSONAPI.configuration.top_level_links_include_pagination - page_options = {} - page_options[:record_count] = record_count if paginator.class.requires_record_count - paginator.links_page_params(page_options.merge(fetched_resources: resource_set)) - else - {} - end - - opts = result_options - opts.merge!(pagination_params: pagination_params) if JSONAPI.configuration.top_level_links_include_pagination - opts.merge!(record_count: record_count) if JSONAPI.configuration.top_level_meta_include_record_count - opts.merge!(page_count: page_count) if JSONAPI.configuration.top_level_meta_include_page_count + opts[:pagination_params] = if paginator && JSONAPI.configuration.top_level_links_include_pagination + page_options = {} + page_options[:record_count] = opts[:record_count] if paginator.class.requires_record_count + paginator.links_page_params(page_options.merge(fetched_resources: resource_set)) + else + {} + end return JSONAPI::RelatedResourcesSetOperationResult.new(:ok, source_resource,