This PR fixes issue #257 where scopes are leaking. The issue can lead to wildly unexpected behavior.
Previously calling .where(..) would mutate the original relation.
Before this change
expect(countries.size).to eq 2
expect(countries.where(name: "US").size).to eq 1
expect(countries.size).to eq 2 # ❌ Fails as previous line mutated the `countries` object
After this change
expect(countries.size).to eq 2
expect(countries.where(name: "US").size).to eq 1
expect(countries.size).to eq 2 # ✅ Passes as the previous line returned a new relation keeping the original
The change also makes the "dirty tracking" in Relation unnecessary as Relations are immutable.
This PR fixes issue #257 where scopes are leaking. The issue can lead to wildly unexpected behavior.
Previously calling
.where(..)
would mutate the original relation.Before this change
After this change
The change also makes the "dirty tracking" in
Relation
unnecessary as Relations are immutable.