Skip to content

Conversation

seanpdoyle
Copy link

Closes #408

Introduce a simple chainable WhereClause class inspired by Active Record.

All methods (including those that integrate with Enumerable) are delegated to WhereClause#all, which itself delegates to Base.find.

By merging parameters through .where-chaining, this commit supports deferred fetching:

people = Person.where(id: 2).where(name: "david")
  # => GET /people.json?id=2&name=david

people = Person.where(id: 2).all(params: { name: "david" })
  # => GET /people.json?id=2&name=david

people = Person.all(from: "/records.json").where(id: 2)
  # => GET /records.json?id=2

@seanpdoyle seanpdoyle force-pushed the where_clause branch 2 times, most recently from d86b0d0 to 6acb99d Compare January 27, 2025 16:14
Closes [rails#408][]

Introduce a simple chainable `WhereClause` class inspired by [Active
Record][].

All methods (including those that integrate with [Enumerable][]) are
delegated to `WhereClause#all`, which itself delegates to `Base.find`.

By merging parameters through `.where`-chaining, this commit supports
deferred fetching:

```ruby
people = Person.where(id: 2).where(name: "david")
  # => GET /people.json?id=2&name=david

people = Person.where(id: 2).all(params: { name: "david" })
  # => GET /people.json?id=2&name=david

people = Person.all(from: "/records.json").where(id: 2)
  # => GET /records.json?id=2
```

[rails#408]: rails#408
[Active Record]: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/relation/where_clause.rb
[Enumerable]: https://ruby-doc.org/3.4.1/Enumerable.html
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.

[Feature Request] Lazy Loading Chained where calls
1 participant