rails/rails — pull request #4543 by jdelStrother (2012-01-19 17:38:09+00:00)
Title: Don't instantiate two objects in collection proxy / find_or_instantiate_by

Hi, I ran into what I believe is a bug in CollectionProxy's method_missing. Given something like

```ruby
class Company
has_many :clients
end

company.clients.find_or_initialize_by_foo('bar')
```

the current code calls find_or_instantiator_by_attributes for the company.clients proxy, then discards the return value and calls find_or_initialize_by on the client scope. The return value then looks rather similar to what you'd
expect from the find_or_instantiator_by_attributes call, but the resulting object isn't in the company.clients collection.

I'm fairly sure that it's just missing an 'elsif', like in the attached commit, but if someone (@jonleighton?) could double-check I'm not missing something stupid that would be appreciated. I believe the problem dates back to https://github.com/rails/rails/commit/86ea94e4d0c228c79b3709f0c667ba90b02e41cd.

I've only been able to try this against our app running 3-1-stable, but the commit applies cleanly to 3-2-stable and master. Any preference which the pull request should be against?