Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ActiveResource::WhereClause #422

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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