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

Add support for cursor: when using in_batches on an ActiveRecord PrivateRelation #2087

Open
SamuelDev opened this issue Nov 22, 2024 · 3 comments
Labels
help-wanted We support this change, and welcome community contributions for it.

Comments

@SamuelDev
Copy link

In 8.0 rails added support for a custom cursor when calling in_batches on a relation. RBI files generated by tapioca do not currently generate this field.

Rails version: 8.1.0
tapioca version: 0.16.3

@amomchilov
Copy link
Contributor

amomchilov commented Nov 25, 2024

Hi @SamuelDev, what's the expected type of this cursor?

Would you like to open a PR to modify one of the sigs here:

when :in_batches
order = ActiveRecord::Batches.instance_method(:in_batches).parameters.include?([:key, :order])
use_ranges = ActiveRecord::Batches.instance_method(:in_batches).parameters.include?([:key, :use_ranges])
common_relation_methods_module.create_method("in_batches") do |method|
method.add_kw_opt_param("of", "1000")
method.add_kw_opt_param("start", "nil")
method.add_kw_opt_param("finish", "nil")
method.add_kw_opt_param("load", "false")
method.add_kw_opt_param("error_on_ignore", "nil")
method.add_kw_opt_param("order", ":asc") if order
method.add_kw_opt_param("use_ranges", "nil") if use_ranges
method.add_block_param("block")
method.add_sig do |sig|
sig.add_param("of", "Integer")
sig.add_param("start", "T.untyped")
sig.add_param("finish", "T.untyped")
sig.add_param("load", "T.untyped")
sig.add_param("error_on_ignore", "T.untyped")
sig.add_param("order", "Symbol") if order
sig.add_param("use_ranges", "T.untyped") if use_ranges
sig.add_param("block", "T.proc.params(object: #{RelationClassName}).void")
sig.return_type = "void"
end
method.add_sig do |sig|
sig.add_param("of", "Integer")
sig.add_param("start", "T.untyped")
sig.add_param("finish", "T.untyped")
sig.add_param("load", "T.untyped")
sig.add_param("error_on_ignore", "T.untyped")
sig.add_param("order", "Symbol") if order
sig.add_param("use_ranges", "T.untyped") if use_ranges
sig.return_type = "::ActiveRecord::Batches::BatchEnumerator"
end

@egiurleo egiurleo added the help-wanted We support this change, and welcome community contributions for it. label Nov 25, 2024
@SamuelDev
Copy link
Author

SamuelDev commented Nov 25, 2024

It is a column name or array of column names. Symbols, possibly strings, unsure of that specific technicality.

@amomchilov
Copy link
Contributor

T.any(String, Symbol) might be a good first approximation. If other types are possible, we can widen the type in the future. It looks like it can be either a single value, or an array of values (it's passed into Array), so perhaps it should be:

T.any(String, Symbol, T::Array[T.any(String, Symbol)])

I won't be able to investigate this myself any time soon, but if you confirm that it works and open a PR, I'd be happy to review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted We support this change, and welcome community contributions for it.
Projects
None yet
Development

No branches or pull requests

3 participants