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

got an error while trying to load a polymorphic association #105

Closed
luizkowalski opened this issue Apr 7, 2021 · 2 comments · Fixed by #107
Closed

got an error while trying to load a polymorphic association #105

luizkowalski opened this issue Apr 7, 2021 · 2 comments · Fixed by #107

Comments

@luizkowalski
Copy link

Hi

I have the following structure:

class User < ApplicationRecord
  ....
  has_many :app_notifications, inverse_of: :user, dependent: :destroy
end

class AppNotification < ApplicationRecord
  has_many :references,
           inverse_of: :app_notification,
           class_name: 'AppNotificationReference',
           dependent: :destroy
end

class AppNotificationReference < ApplicationRecord
  acts_as_paranoid

  belongs_to :app_notification, required: true, inverse_of: :references
  belongs_to :notifiable, -> { with_deleted }, polymorphic: true, required: true
end

I don't have any other validations.

after adding goldiloader i started seeing this error on my specs:

ArgumentError:
       Polymorphic associations do not support computing the class.
     # /usr/local/bundle/gems/goldiloader-4.0.0/lib/goldiloader/active_record_patches.rb:82:in `eager_loadable?'
     # /usr/local/bundle/gems/goldiloader-4.0.0/lib/goldiloader/active_record_patches.rb:114:in `eager_loadable?'
     # /usr/local/bundle/gems/goldiloader-4.0.0/lib/goldiloader/active_record_patches.rb:104:in `auto_include?'
     # /usr/local/bundle/gems/goldiloader-4.0.0/lib/goldiloader/active_record_patches.rb:121:in `load_with_auto_include'
     # /usr/local/bundle/gems/goldiloader-4.0.0/lib/goldiloader/active_record_patches.rb:143:in `find_target'
     # ./spec/domains/payments/card/services/authorization_handler_spec.rb:252:in `block (6 levels) in <top (required)>'


expect(app_notification.references.first.notifiable).to eq(payment_card)

I tried to add -> { auto_include(false) } to disable eager loading to the associations on app_notification, even on user. nothing helped.

Is this an issue or misconfiguration?

@luizkowalski luizkowalski changed the title got an error while trying to load an polymorphic association got an error while trying to load a polymorphic association Apr 7, 2021
@jturkel
Copy link
Member

jturkel commented Apr 7, 2021

Thanks for reporting this issue. I'm able to reproduce the problem which occurs whenever using a polymorphic association with a scope block in Rails 6.0+. I'll work on getting a fix out this week.

@jturkel
Copy link
Member

jturkel commented Apr 9, 2021

Fix released in 4.0.1. Thanks for reporting the issue @luizkowalski.

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

Successfully merging a pull request may close this issue.

2 participants