You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it's nice to be able to access a version of an ActiveRecord object before certain changes are applied, e.g.:
classFoo < ActiveRecord::Basedeffoobarsome_attributeendaround_update:bardefbarppself.foobar# At this point, I'd like to be able to inspect the 'old' stateyieldppself.foobarendend
Currently, ActiveRecord::Dirty provides some methods to inspect changes and older values of specific attributes through changes and *_was, but not the entire previous state. Having access to it would allow you to call instance methods using the old state.
I propose to add the following instance method to ActiveRecord::Dirty:
So we can replace self by self_was before the yield and get the behavior that we want.
If this is not the right repo to suggest this in, please let me know. Apologies for ignoring the issue template, but it was not really applicable for a feature request, so ignoring it seemed more appropriate then shoehorning this suggestion into it.
The text was updated successfully, but these errors were encountered:
Hi @TiesWestendorp thanks for the issue. We don't accept feature requests on the issues tracker, we reserve it for bugs in the framework. I'm not sure how possible this would be to implement or whether it's really useful to a wide range of applications. It would probably be best for you to post on the forum and see what others think. If you want to try out an implementation please open a PR. If you need help contributing, you can use the contributors discord. Thanks for understanding!
Sometimes it's nice to be able to access a version of an
ActiveRecord
object before certain changes are applied, e.g.:Currently,
ActiveRecord::Dirty
provides some methods to inspect changes and older values of specific attributes throughchanges
and*_was
, but not the entire previous state. Having access to it would allow you to call instance methods using the old state.I propose to add the following instance method to
ActiveRecord::Dirty
:So we can replace
self
byself_was
before the yield and get the behavior that we want.If this is not the right repo to suggest this in, please let me know. Apologies for ignoring the issue template, but it was not really applicable for a feature request, so ignoring it seemed more appropriate then shoehorning this suggestion into it.
The text was updated successfully, but these errors were encountered: