method

with_exclusive_scope

rails latest stable - Class: ActiveRecord::Base

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.1.0) is shown here.

with_exclusive_scope(method_scoping = {}, &block)
protected

Works like with_scope, but discards any nested properties.

3Notes

with_exclusive_scope example by Ramon broken in latest Rails

k776 · Aug 13, 20093 thanks

The example Ramon gave works within the model itself, i.e.

class Article
def closed
  with_exclusive_scope { find(:all) }
end
end

However, from what I can see, this approach does not work within a controller. You may be wanting to use

Article.with_exclusive_scope { find(:all) }  #=> "SELECT * FROM 'articles'

But it will error out about find(:all) not existing on ArticlesController. To get around this, you must now do

Article.with_exclusive_scope { Article.find(:all) }  #=> "SELECT * FROM 'articles'

In otherwards, find(:all) isn't being executed in the scope of the model, but in the controller in which its called.

Took me a minute or two to find out, so I thought I'd let others know.

In Rails3 use "unscoped" instead

fpauser · Aug 11, 20103 thanks

The +with_exclusive_scope+ examples no longer work in Rails3 because +with_exclusive_scope+ is now a protected method which can and should not be used in a controller. Use the new +unscoped+ method instead:

Article.unscoped

For mor details and examples have a look at: http://github.com/rails/rails/commit/bd1666ad1de88598ed6f04ceffb8488a77be4385.

How to use with exclusive scope

Ramon · Jun 11, 20092 thanks

=== Code example Article.with_exclusive_scope { find(:all) } #=> "SELECT * FROM 'articles'

from http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping