Skip to content

Conversation

@pfeiffer
Copy link
Contributor

@pfeiffer pfeiffer commented Oct 4, 2022

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.

@pfeiffer
Copy link
Contributor Author

See also the #268 as an alternative which addresses the root of the issue.

@kbrock
Copy link
Collaborator

kbrock commented Mar 27, 2023

Going with #268

@kbrock kbrock closed this Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants