-
Notifications
You must be signed in to change notification settings - Fork 133
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
Kaminari pagination is not supported by Tapioca #1859
Comments
The solution above works pretty well, but it's not aware of methods like
# typed: ignore
require 'tapioca/dsl/helpers/active_record_constants_helper'
require 'kaminari/activerecord/active_record_model_extension'
module Tapioca
module Dsl
module Compilers
class Kaminari < Tapioca::Dsl::Compiler
include Tapioca::Dsl::Helpers::ActiveRecordConstantsHelper
def self.gather_constants
all_classes
.select { |c| c < ::Kaminari::ActiveRecordModelExtension }
.reject(&:abstract_class?)
end
def decorate
root.create_path(constant) do |model|
generate_page_method(
model.create_module(RelationMethodsModuleName),
RelationClassName,
)
generate_page_method(
model.create_module(AssociationRelationMethodsModuleName),
AssociationRelationClassName,
)
model.create_extend(RelationMethodsModuleName)
end
end
private
def generate_page_method(mod, return_type)
mod.create_method(
'page',
parameters: [create_opt_param('num', type: 'T.any(Integer, String)', default: 'nil')],
return_type: "T.all(#{return_type}, Kaminari::PageScopeMethods, Kaminari::ActiveRecordRelationMethods)",
)
end
end
end
end
end |
amomchilov
changed the title
kaminari pagination is not supported by tapioca
Kaminari pagination is not supported by Tapioca
Dec 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to update tapioca from 0.12.0 to 0.13.1 results in this error:
Investigation
The page method is defined on the class by kaminari:
https://github.com/kaminari/kaminari/blob/9182d065c144afa45c6b7cf444f810bea1fd7201/kaminari-activerecord/lib/kaminari/activerecord/active_record_model_extension.rb#L14-L23
But attempting to introspect it at runtime yields nothing:
This is because it is delegated by https://github.com/rails/rails/blob/d37c533139f70efdcd95f8dadd48c10eba429f94/activerecord/lib/active_record/relation/delegation.rb#L71-L88
Which is generated on demand when the method is missing:
https://github.com/rails/rails/blob/d37c533139f70efdcd95f8dadd48c10eba429f94/activerecord/lib/active_record/relation/delegation.rb#L115-L124
Attempting the same as above after calling the method once does yield something a bit more interesting:
The same can be achieved by calling
Model.generate_relation_method(:page)
Workaround
Adding this in
config/initializers/kaminari.rb
makes tapioca generate the methods:The text was updated successfully, but these errors were encountered: