r/ruby • • Oct 21 '26

Merging Relations: Use merge to share scopes in Rails

Post image

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

17 Upvotes

0 comments sorted by