rails/rails — pull request #11694 by Empact (2013-08-01 06:05:15+00:00)
Title: Accessing an association before its owner is saved should not make the association useless for doing `update_all`, etc.

A failing test which shows that when a collection association 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

more evidence here: https://gist.github.com/Empact/5865555
```
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.
```