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

HABTM Association causes sync() to save model. #64

Open
SirRawlins opened this issue May 10, 2017 · 1 comment
Open

HABTM Association causes sync() to save model. #64

SirRawlins opened this issue May 10, 2017 · 1 comment

Comments

@SirRawlins
Copy link

I've been experimenting today and found that if you have a HABTM association which is set through disposable such as tag_ids then the underlying active record will save itself when the setter for that attribute is invoked.

This means that calling sync() on disposable can inadvertently save the underlying record. This would presumably also happen with has_many associations of a similar nature that AR also likes to autosave.

This is a quirk with AR rather than anything specific to Disposable, but after a Gitter conversation with @apotonick he asked me to file this as a reminder to anyone.

@dmitry
Copy link

dmitry commented Jun 25, 2020

More on that: https://discuss.rubyonrails.org/t/inconsistent-collection-setter-behaviour-has-many-has-many-through/72404
Would be good to change this behavior in the next major versions of activerecord.

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