gem_rbs_collection icon indicating copy to clipboard operation
gem_rbs_collection copied to clipboard

Fix kaminari-activerecord relation type

Open okuramasafumi opened this issue 2 months ago • 6 comments

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 avatar Oct 19 '25 06:10 okuramasafumi

@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.

github-actions[bot] avatar Oct 19 '25 06:10 github-actions[bot]

I’m checking this because I think we might also need to update the tests. :loading:

Little-Rubyist avatar Oct 20 '25 09:10 Little-Rubyist

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.

okuramasafumi avatar Nov 05 '25 13:11 okuramasafumi

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.

ksss avatar Nov 05 '25 14:11 ksss

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.

okuramasafumi avatar Nov 07 '25 05:11 okuramasafumi

In RBS, we cannot redefine the same method name, nor can we invalidate existing definitions. Optional means would require advanced hacks.

ksss avatar Nov 07 '25 08:11 ksss