Skip to content

Add ActiveHash::Relation#or to support OR-like queries#343

Open
opsys-saito wants to merge 1 commit intoactive-hash:masterfrom
opsys-saito:feature/add-or-support
Open

Add ActiveHash::Relation#or to support OR-like queries#343
opsys-saito wants to merge 1 commit intoactive-hash:masterfrom
opsys-saito:feature/add-or-support

Conversation

@opsys-saito
Copy link

Summary

This PR adds support for ActiveHash::Relation#or, allowing OR-like queries similar to ActiveRecord:

Model.where(condition_a).or(Model.where(condition_b))

The implementation returns a new relation representing the union of both result sets, deduplicated by id.

Behavior

  • Supports chaining:
    Model.where(a: 1).or(Model.where(a: 2)).where(b: 3)
  • Deduplicates records based on id
  • Raises an ArgumentError when combining relations from different models

Implementation 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:

  • Union of two relations
  • Deduplication behavior
  • Chainability after or
  • Error handling for mismatched models

@opsys-saito opsys-saito changed the title Add ActiveHash::Relation#or to support OR-like queriesAdd Relation#or support Add ActiveHash::Relation#or to support OR-like queries Feb 19, 2026
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.

1 participant

Comments