github/rails — pull request #24 by charliesome (2013-10-25 21:07:24+00:00)
Title: Avoid extension when instantiating extended association

Say we have some code like this:

```ruby
class Foo < ActiveRecord::Base
has_many :widgets, extend: SomeModule
end
```

Whenever we access the `widgets` association on an instance of `Foo`, ActiveRecord will dynamically extend `SomeModule` into the association object. This has the effect of globally invalidating our constant cache on 1.9.

This pull request changes ActiveRecord's behaviour so it will re-use the same class with all the right extension modules included. This should avoid continual cache invalidations and should improve cache hit rates when calling methods on these objects since the same class will be used every time.

cc @github/perf @github/rails