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

Conflict with gems that override ActiveRecord::Relation#calculate #244

Closed
RobertoSchneiders opened this issue Nov 6, 2020 · 2 comments
Closed

Comments

@RobertoSchneiders
Copy link

RobertoSchneiders commented Nov 6, 2020

I have an issue with groupdate when combined with the latest version of activerecord-sqlserver-adapter. The sqlserver-adapter gem is overriding the ActiveRecord::Relation#calculate with a prepend as you can see here. with that, the groupdate calculate method is never executed, causing weird issues that are not obvious until you start debugging the gem.

I was able to fix the issue by prepending the groupdate calculate method as well, so both methods are executed (you have to be aware of the load order). This is the patch I used:

module Groupdate
  module RelationPatch
    extend ActiveSupport::Concern

    def calculate(*args, &block)
      default_value = [:count, :sum].include?(args[0]) ? 0 : nil
      Groupdate.process_result(self, super, default_value: default_value)
    end
  end
end

ActiveRecord::Relation.prepend(Groupdate::RelationPatch)

can we change groupdate to prepend instead of including the relation concern? if we do that I would be able to fix this issue just by moving the groupdate gem to the end of the gemfile instead of having to patch it.

@ankane
Copy link
Owner

ankane commented Nov 6, 2020

Hey @RobertoSchneiders, I think it'd be better for activerecord-sqlserver-adapter to use super for non SQL Server adapters.

@ankane
Copy link
Owner

ankane commented Jan 13, 2021

Cleaning up issues

@ankane ankane closed this as completed Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants