r/ruby • u/6stringfanatic • 15h ago
Merging Relations: Use merge to share scopes in Rails
11
Upvotes
I wrote a post about using ActiveRecord::Relation#merge to share scopes across models in Rails.
The example shows how duplicating a query can lead to inconsistent behaviour, and how extracting the rule into a named scope avoids that.
https://pushfromkush.com/publications/merging-relations-scopes-in-rails