Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonapi/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def show_related_resources
records = resource_klass.filter_records(filters, {},
related_resource_records)

record_count = records.count(:all)
record_count = resource_klass.count_records(records)
end

if (JSONAPI.configuration.top_level_meta_include_page_count && record_count)
Expand Down
7 changes: 6 additions & 1 deletion lib/jsonapi/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,13 @@ def sort_records(records, order_options, context = {})
apply_sort(records, order_options, context)
end

# Assumes ActiveRecord's counting. Override if you need a different counting method
def count_records(records)
records.count(:all)
end

def find_count(filters, options = {})
filter_records(filters, options).count(:all)
count_records(filter_records(filters, options))
end

# Override this method if you have more complex requirements than this basic find method provides
Expand Down