Repository navigation
Fix scopes combined with OR combinator not working - #1622
scarroll32 with Copilot wants to merge 6 commits into
Conversation
…ining translations (#1614) * Initial plan * Changes before error encountered Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com> * Improve sorted translations docs --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
|
Note Comment from Claude (Claude Code), acting on behalf of @scarroll32. Closing as part of clearing the PR backlog ahead of 5.0.0 (#1640). This is one of a batch of PRs opened by the Copilot coding agent in September 2025. They have aged out: The underlying issue stays open. Nothing is being dismissed on the merits — the bug reports behind these PRs are still valid and still wanted. What's being retired is a batch of stale machine-generated branches that cost more to salvage than to redo. If you're affected by the underlying issue, the most useful contribution is a PR with a failing spec that reproduces it against current |
Fixes an issue where scopes combined with the
:orcombinator would not generate proper OR logic in SQL queries.Problem
When using scopes with the OR combinator, the generated SQL would ignore the OR logic and apply scopes with AND semantics instead:
Root Cause
Scopes were applied immediately during search building via
@context.chain_scope(), bypassing the visitor pattern that handles OR/AND combinator logic. This meant scopes were always chained with AND semantics regardless of the specified combinator.Solution
Two-part minimal fix:
.or()methodThe fix handles:
Person.ransack(red: true, green: true, m: :or)Person.ransack(red: true, name_cont: 'John', m: :or)Person.ransack(red: true, green: true)Changes Made
lib/ransack/search.rb: Modifiedadd_scopeto defer scope application when OR combinator is usedlib/ransack/adapters/active_record/context.rb: Enhancedevaluatemethod to handle scope OR combinationsspec/ransack/scope_or_combinator_spec.rb: Added comprehensive test coverageBackward Compatibility
This change is fully backward compatible. The default AND behavior remains completely unchanged, and the fix only activates when both OR combinator and scopes are present.
Closes #[issue_number]
Additional instructions:
Fixes #1110
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.