[WIP] Make searches chainable using and/or #1591
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementing chainable
and
/or
methods for Ransack searchesAnalysis
The issue requests adding chainable methods like
search_parents.or(search_children)
to make merging searches more intuitive. Currently, users need to:Plan
and
andor
methods to theSearch
classChainedSearch
class to handle combination of searchesImplementation Details
Core Changes
and()
andor()
methods toSearch
class - These return a newChainedSearch
instanceChainedSearch
class - Handles combination of multiple searches with proper context sharingKey Features
search1.and(search2).or(search3)
works correctlyAPI Examples
Simple OR operation:
Chained operations:
Mixed AND/OR:
Test Results
✅ Basic AND operations:
search1.and(search2)
✅ Basic OR operations:
search1.or(search2)
✅ Chained operations:
search1.or(search2).or(search3)
✅ Mixed operations:
search1.and(search2).or(search3)
✅ Proper SQL generation with correct grouping
✅ Comprehensive test suite added
✅ Documentation updated with examples
The implementation successfully addresses the core issue by providing an intuitive chainable API that handles context sharing automatically, making search combination much simpler for users.
Fixes #417
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.