Skip to content

Commit 2c4e452

Browse files
takaokoujiclaude
andcommitted
Fix unstable ordering in Book associations for PostgreSQL
Add explicit ordering by id to Book's book_comments and approved_book_comments associations. Without explicit ordering, PostgreSQL returns relationship data in non-deterministic order, causing cache test failures where warmup response differs from normal response. The previous fix added default_sort to BookCommentResource, which handles collection queries, but didn't affect relationship linkage data in included resources. This fix ensures stable ordering at the ActiveRecord association level. Fixes: RequestTest#test_pagination_related_resources_data_includes Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0914344 commit 2c4e452

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

test/fixtures/active_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ def destroy
647647
end
648648

649649
class Book < ActiveRecord::Base
650-
has_many :book_comments
651-
has_many :approved_book_comments, -> { where(approved: true) }, class_name: "BookComment"
650+
has_many :book_comments, -> { order(:id) }
651+
has_many :approved_book_comments, -> { where(approved: true).order(:id) }, class_name: "BookComment"
652652

653653
has_and_belongs_to_many :authors, join_table: :book_authors, class_name: "Person"
654654

0 commit comments

Comments
 (0)