Commit dbb5e1a
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
| 661 | + | |
| 662 | + | |
661 | 663 | | |
662 | 664 | | |
663 | 665 | | |
| |||
0 commit comments