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

Instance Variables and Re-used Objects #124

Open
stcorbett opened this issue Jul 10, 2016 · 4 comments
Open

Instance Variables and Re-used Objects #124

stcorbett opened this issue Jul 10, 2016 · 4 comments
Labels

Comments

@stcorbett
Copy link

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.

@syguer
Copy link
Collaborator

syguer commented Apr 5, 2017

Ref #125

@syguer syguer added the v2.0.0 label Apr 5, 2017
@syguer
Copy link
Collaborator

syguer commented Apr 5, 2017

I agree that finder should returns fresh instance of ActiveHash whether setting instance variables or not.

@rockotseng
Copy link

Hi, issue still happen in v2.1.0, any plan on this one?

@syguer
Copy link
Collaborator

syguer commented Jul 18, 2019

No progress yet.
If you are interested in this issue, PR is welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants