rails/rails — pull request #10367 by neerajdotname (2013-04-27 18:36:52+00:00)
Title: first_or_create fix for has_many :through

fixes #10144

`physician.patients.first_or_create` creates the association
record.

However `physician.patients.where(name: 'neeraj').first_or_create`
does not create the association record.

In the first case `first_or_create` is being invoked on
`CollectionProxy` instance. However in the second instance
`physician.patients.where(name: 'neeraj')` returns a `Relation`
object and not `CollectionProxy` object.

Fix is to check if the relation object happens to have
`proxy_association` then invoke `create` on that
`proxy_association`.

/cc @jonleighton