rails/rails — pull request #6579 by amatsuda (2012-06-01 06:04:51+00:00)
Title: modulize AR::NullRelation

Current implementation of `AR::Relation#none` replaces the `Relation` instance, and consequently clears all extension methods defined on self by proceeding scopes.

For example, with this AR model and scope,

```ruby
class User < ActiveRecord::Base
scope :anonymous_extension, -> { scoped } do
def one
1
end
end
end
```

The `one` method was removed from `none`ed relation before this patch,

```
> User.anonymous_extension.none.one
NoMethodError: undefined method `one' for []:ActiveRecord::NullRelation
```

Now `one` properly calls the extension method.

```
> User.anonymous_extension.none.one
=> 1
```