Add ActiveHash::Relation#or to support OR-like queries#343
Add ActiveHash::Relation#or to support OR-like queries#343kbrock merged 1 commit intoactive-hash:masterfrom
Conversation
kbrock
left a comment
There was a problem hiding this comment.
This looks sweet.
Could you add a or() with anoother operator, like an order?
|
Thanks! That's a great point 👍 Just to clarify — would it make sense to support In that case, we could raise an error when they differ, similar to ActiveRecord’s behavior for incompatible relations. Happy to adjust depending on your preference! |
|
@opsys-saito sorry. I was not clear Please just add a test with an order. Something like? Hoping Model.where(:id => 1).or(Model.where(:id => [2, 3])).order(:id => :desc)Maybe using country - just throw an order in there ensure it works, and call it a day. |
6b84886 to
07dbfdb
Compare
|
Thanks for the clarification! I've added a test to ensure |
kbrock
left a comment
There was a problem hiding this comment.
This looks great. thanks
Just waiting for Green then I'll merge
|
@kbrock |
Summary
This PR adds support for
ActiveHash::Relation#or, allowing OR-like queries similar to ActiveRecord:The implementation returns a new relation representing the union of both result sets, deduplicated by
id.Behavior
idArgumentErrorwhen combining relations from different modelsImplementation Notes
Since ActiveHash operates entirely in memory, this implementation performs a union of the evaluated result sets rather than merging condition trees.
The returned value remains an
ActiveHash::Relation, preserving chainability and compatibility with existing APIs.Tests
Added specs covering: