Skip to content

Conversation

seanpdoyle
Copy link
Contributor

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
@rafaelfranca rafaelfranca force-pushed the where_clause branch 2 times, most recently from c45d3df to 07a9db1 Compare September 11, 2025 16:15
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
@rafaelfranca rafaelfranca merged commit 4a3da35 into rails:main Sep 11, 2025
19 checks passed
@seanpdoyle seanpdoyle deleted the where_clause branch September 11, 2025 16:33
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
2 participants