-
Notifications
You must be signed in to change notification settings - Fork 79
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
Kredis methods are undefined in production for non-ActiveRecord models #60
Comments
Thanks for reporting! |
@fxn Would you know what's up here? |
Yo! Yes, @EmCousin guess is correct. Eager loading happens in the finisher here, and the This relative order has been the same for a long time. I'd suspect that if you ran development mode with eager loading enabled, you'll be able to reproduce and test a solution locally. I believe the idiomatic thing to do would be to define a load hook for Active Model. But that would need a release of Rails. Meanwhile, @EmCousin while a solution for Kredis is worked out, in your application you can do the same. Throw this in an initializer or # See https://github.com/rails/kredis/issues/60.
ActiveSupport.on_load(:active_record) do
ActiveModel::Model.include Kredis::Attributes
end I have not tested this, but module inclusion is idempotent, so this won't interfere with Kredis doing the same later. That way, you can leave your application code clean and just remove the trick when an update upstream makes it no longer necessary. |
Thanks @fxn!
Looking forward to the update! 🙂 |
@EmCousin cool!
What do you mean? |
I mean that this: # See https://github.com/rails/kredis/issues/60.
ActiveSupport.on_load(:active_record) do
ActiveModel::Model.include Kredis::Attributes
end does not have to be put straight into |
@EmCousin perfect :). |
Hi,
First, thank you for this great gem.
I'm encountering an error when trying to use Kredis methods like
kredis_string
,kredis_json
, etc. in a class that inherits from a base class that includesActiveModel::Model
. This issue does not occur in development, only in production, preventing the app to boot.The error :
How to reproduce the error:
I wonder it this might have something to do with the way
Kredis::Attributes
gets included inActiveModel::Model
here. Could it be due to the fact it is called inconfig.after_initialize
callback instead of a load hook like it's done with ActiveRecord?Just trying to wrap my head around this. The current workaround I use is to include explicitly
Kredis::Attributes
:Is it how we should actually use it?
Background
The text was updated successfully, but these errors were encountered: