Skip to content

Commit 5eb0869

Browse files
committed
Merge pull request #720 from cerebris/count_refactor
Add count_records method to allow easier override for non activerecor…
2 parents 6104afb + 0bcde39 commit 5eb0869

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/jsonapi/processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def show_related_resources
160160
records = resource_klass.filter_records(filters, {},
161161
related_resource_records)
162162

163-
record_count = records.count(:all)
163+
record_count = resource_klass.count_records(records)
164164
end
165165

166166
if (JSONAPI.configuration.top_level_meta_include_page_count && record_count)

lib/jsonapi/resource.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,13 @@ def sort_records(records, order_options, context = {})
628628
apply_sort(records, order_options, context)
629629
end
630630

631+
# Assumes ActiveRecord's counting. Override if you need a different counting method
632+
def count_records(records)
633+
records.count(:all)
634+
end
635+
631636
def find_count(filters, options = {})
632-
filter_records(filters, options).count(:all)
637+
count_records(filter_records(filters, options))
633638
end
634639

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

0 commit comments

Comments
 (0)