Skip to content

Commit dbb5e1a

Browse files
takaokoujiclaude
andcommitted
Add default_scope to BookComment for stable ordering
The previous fix adding order(:id) to Book's has_many :book_comments association was not sufficient. In some contexts (particularly with Rails 8 and caching), the association scope was not being applied consistently, leading to non-deterministic ordering in PostgreSQL. Adding default_scope { order(:id) } to BookComment ensures that all queries against this model return results in a consistent order, regardless of how they are accessed (direct queries, associations, eager loading, etc.). This is a test-only change that ensures stable test results across different Rails versions and database engines. Fixes: RequestTest#test_pagination_related_resources_data_includes (flaky on Rails 8.1.2 + PostgreSQL) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent ae2e6af commit dbb5e1a

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

test/fixtures/active_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ class Book < ActiveRecord::Base
658658
end
659659

660660
class BookComment < ActiveRecord::Base
661+
default_scope { order(:id) }
662+
661663
belongs_to :author, class_name: 'Person', foreign_key: 'author_id'
662664
belongs_to :book
663665

0 commit comments

Comments
 (0)