Skip to content

Bug > attribute_changed? flag is not correctly set when modifying the array #13

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

Open
saurabhnanda opened this issue Nov 19, 2012 · 7 comments

Comments

@saurabhnanda
Copy link

Here's how to reproduce this bug:

> ar_object.some_pg_array.push(1)
> ar_object.some_pg_array_changed?
=> false

> ar_object.some_pg_array = [1, 2, 3]
> ar_object.some_pg_array_changed?
=> true
@funny-falcon
Copy link
Owner

:(
could you say your version of ActiveRecord ?

@saurabhnanda
Copy link
Author

3.1.1

@saurabhnanda
Copy link
Author

Were you able to reproduce this?

@funny-falcon
Copy link
Owner

I believe you :)
Unfortunately, it not easy to fix, cause it will be necessary to always save an array's copy somewere (and I really do not like to save a copy on every fetch, even you will not change array).

I really suggest you to use ar_object.some_pg_array = [1, 2, 3] syntax.

In the reality I should freeze fetched arrays, so that ar_object.some_pg_array.push(1) raise error. I regret I hadn't do it at the very beginning. And now I could not do it cause many people use this gem :(

@saurabhnanda
Copy link
Author

:)

Why don't you put a warning/deprecation notice on some_pg_array.push and see how many people write back?

In future you can freeze the PG arrays then?

@funny-falcon
Copy link
Owner

Why don't you put a warning/deprecation notice on some_pg_array.push and see how many people write back?

Overwrite Array? Or fetch arrays as Array's subclass instances?

@saurabhnanda
Copy link
Author

Fetch PG arrays as PGArray < Array probably?

On Fri, Nov 23, 2012 at 4:15 PM, Sokolov Yura [email protected]:

Why don't you put a warning/deprecation notice on some_pg_array.push and
see how many people write back?

Overwrite Array? Or fetch arrays as Array's subclass instances?


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-10655999.

http://www.saurabhnanda.com

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

No branches or pull requests

2 participants