Skip to content

Commit 01bdcd4

Browse files
committed
Fix unstable ordering in BookCommentResource for PostgreSQL
Add default_sort to Api::V2::BookCommentResource to ensure stable ordering across cache and non-cache scenarios. Without explicit ordering, PostgreSQL may return results in different orders, causing cache test failures. Fixes: RequestTest#test_pagination_related_resources_data_includes
1 parent 878520c commit 01bdcd4

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

test/fixtures/active_record.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,11 @@ class BookCommentResource < JSONAPI::Resource
20222022
records.where(BookComment.arel_table[:body].matches("%#{value[0]}%"))
20232023
}
20242024

2025+
# Add default sort to ensure stable ordering across cache/non-cache scenarios
2026+
def self.default_sort
2027+
[{field: 'id', direction: :asc}]
2028+
end
2029+
20252030
class << self
20262031
def book_comments
20272032
BookComment.arel_table

0 commit comments

Comments
 (0)