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

A failing test which shows that when a collection association is accessed before saving the owner, the proxy caches the #bind_values without the owner's id. #11001

Closed

Conversation

Empact
Copy link
Contributor

@Empact Empact commented Jun 18, 2013

This causes calls like: owner.association.update_all to behave unexpectedly
in this case, because they try to act on association objects where
owner_id is null.

This is related to #bind_values being set on first access at:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_proxy.rb#L37

Not sure how to properly deal with this, but it is the case that calling update all on
the #scope of the association works.

is accessed before saving the owner, the proxy caches the #bind_values
from before the owner being persisted.

This causes calls like: owner.association.update_all to behave unexpectedly
in this case, because they try to act on association objects where
owner_id is null.

This is related to #bind_values being set on first access at:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_proxy.rb#L37
@Empact
Copy link
Contributor Author

Empact commented Jun 25, 2013

/cc @jonleighton

@Empact
Copy link
Contributor Author

Empact commented Jun 26, 2013

Hey @carlosantoniodasilva, this is a Rails 4 regression, with more evidence here: https://gist.github.com/Empact/5865555

The output for the above is:

Active Record 3.2.13
-- create_table(:firms, {:force=>true})
   -> 0.1371s
-- create_table(:clients, {:force=>true})
   -> 0.0005s
1 clients. 1 expected.
1 clients updated. 1 expected.
Active Record 4.0.0
-- create_table(:firms, {:force=>true})
   -> 0.1606s
-- create_table(:clients, {:force=>true})
   -> 0.0004s
1 clients. 1 expected.
0 clients updated. 1 expected.

Should I re-open this request on 4-0-stable?

@steveklabnik
Copy link
Member

All pull requests should be opened against master, they'll be backported appropriately.

That said let's see if @carlosantoniodasilva agrees this is actually a bug.

@Empact
Copy link
Contributor Author

Empact commented Aug 1, 2013

Hit this again in tests, reopened against master as #11694

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

Successfully merging this pull request may close these issues.

3 participants