-
Notifications
You must be signed in to change notification settings - Fork 162
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
[MERGED] ActiveModel.reload has to clear the internal cache [MERGED] #507
Conversation
c6c2b17
to
375bb11
Compare
Otherwise, one will get stale cache on the freshly reloaded model e.g. `current_state` would return outdated result.
375bb11
to
843cee3
Compare
Unrelated to the changes made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR it's just rubocop started to complain about this for some reason and I had to make the change.
|
||
define_method(:reload) do |*a| | ||
instance = super(*a) | ||
if instance.respond_to?(:state_machine, true) | ||
instance.state_machine.reset | ||
end | ||
instance | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this will only work if
include Statesman::Adapters::ActiveRecordQueries
is applied to the target model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…-the-cache ActiveModel.reload has to clear the internal cache
In #417 the
state.reset
method was added and suggested to be used together withactive_record.reload
.In this PR, I make sure that we apply this logic automatically if
Statesman::Adapters::ActiveRecordQueries
included to the model definition so the users don't have to do this themself.