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

activerecord: Support QueryObject Pattern for AR::Base.scope #731

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

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Nov 23, 2024

ActiveRecord::Base.scope can take an object having call method as 2nd argument "body". QueryObject pattern is a technique to implement complicated query using a class having call method.

This allows to pass a QueryObject (_Callable) to the scope definition.

refs:

Copy link

@tk0miya Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

activerecord

You changed RBS files for an existing gem.
You can merge this PR yourself because you are a reviewer of this gem.
Just comment /merge to merge this PR.

You can also request a review from other reviewers if you want.

ActiveRecord::Base.scope can take an object having `call` method as 2nd
argument "body".  QueryObject pattern is a technique to implement
complicated query using a class having `call` method.

This allows to pass a QueryObject (_Callable) to the scope definition.

refs:

* https://github.com/rails/rails/blob/v6.0.6.1/activerecord/lib/active_record/scoping/named.rb#L171
* https://github.com/Selleo/pattern/blob/master/lib/patterns/query.rb
* https://takaokouji.github.io/output/query-object/ (Japanese)
@tk0miya tk0miya force-pushed the activerecord/support_queryobject_pattern branch from 47f2ae3 to ca854d3 Compare November 24, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant