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
I run into some trouble with ActiveHash when I set some per-request data on instance variables of an ActiveHash instance. I expected the ActiveHash finder methods to return fresh objects the way ActiveRecord does when you call find or where().first or whatnot.
I wrote a patch that separates the original state of the records in an ActiveHash sub-class from the records that are being passed around in the rest of the application. There is a bit of memory overhead to passing cloned objects instead of references to the same object, but that is true for ActiveRecord as well and it does not gum things up too much. I will submit a PR so you guys can have a look.
Alternatively to cloning objects, ActiveHash could freeze the records so they raise errors when developers try to set instance variables on them. This would give developers a better notion that the object they are using is not a clean/fresh copy like they'd expect it to be from ActiveRecord.
The text was updated successfully, but these errors were encountered:
I run into some trouble with ActiveHash when I set some per-request data on instance variables of an ActiveHash instance. I expected the ActiveHash finder methods to return fresh objects the way ActiveRecord does when you call
find
orwhere().first
or whatnot.I wrote a patch that separates the original state of the records in an ActiveHash sub-class from the records that are being passed around in the rest of the application. There is a bit of memory overhead to passing cloned objects instead of references to the same object, but that is true for ActiveRecord as well and it does not gum things up too much. I will submit a PR so you guys can have a look.
Alternatively to cloning objects, ActiveHash could freeze the records so they raise errors when developers try to set instance variables on them. This would give developers a better notion that the object they are using is not a clean/fresh copy like they'd expect it to be from ActiveRecord.
The text was updated successfully, but these errors were encountered: