Fix kaminari-activerecord relation type
Previously, we needed to add our own handwritten type to AR model.
class Talk < ApplicationRecord
class ActiveRecord_Relation
def page: (untyped) -> self
def per: (Integer) -> self
end
end
This is fixed by this Pull Request.
@okuramasafumi 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
kaminari-activerecord
You changed RBS files for an existing gem. This gem does not have reviewers. So you can merge this PR immediately if the CI passes. We recommend you add yourself to the reviewers for this gem.
I’m checking this because I think we might also need to update the tests. :loading:
OK, so now I noticed that what is a problem. The example below works:
Talk.page(1).per(10)
But this doesn't:
Talk.all.page(1).per(10)
I believe it's because all returns a type which we don't expect. I have not investigated it well yet, though.
page method of kaminari can be dynamically changed by configuration.
https://github.com/kaminari/kaminari/blob/master/README.md#changing-page_method_name
If we fix the name here, it may be useful for many applications that have not changed their settings, but it may cause confusion for some applications that have changed their settings. For more correct typing, I recommend writing types that match the configuration on the application side.
page method of kaminari can be dynamically changed by configuration.
Right, but if it's not common, adding page method makes sense. Writing types manually could be optional.
In RBS, we cannot redefine the same method name, nor can we invalidate existing definitions. Optional means would require advanced hacks.