diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-07-27 12:01:25 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-07-27 13:34:12 +0100 |
commit | 6a81ccd69d96f36f4322ef927191ab5a35e68d68 (patch) | |
tree | eefd3b92255fa3969e412c88633332a47808f3c5 /activerecord/lib/active_record/scoping | |
parent | f1afd7765c2a35cc77e1ee40466db36f181e29f5 (diff) | |
download | rails-6a81ccd69d96f36f4322ef927191ab5a35e68d68.tar.gz rails-6a81ccd69d96f36f4322ef927191ab5a35e68d68.tar.bz2 rails-6a81ccd69d96f36f4322ef927191ab5a35e68d68.zip |
ActiveRecord::Base.all returns a Relation.
Previously it returned an Array.
If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.
In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
Diffstat (limited to 'activerecord/lib/active_record/scoping')
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 2af476c1ba..54de30fe7d 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -12,33 +12,30 @@ module ActiveRecord extend ActiveSupport::Concern module ClassMethods - # Returns an anonymous \scope. + # Returns an <tt>ActiveRecord::Relation</tt> scope object. # - # posts = Post.scoped + # posts = Post.all # posts.size # Fires "select count(*) from posts" and returns the count # posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects # - # fruits = Fruit.scoped + # fruits = Fruit.all # fruits = fruits.where(:color => 'red') if options[:red_only] # fruits = fruits.limit(10) if limited? # - # Anonymous \scopes tend to be useful when procedurally generating complex - # queries, where passing intermediate values (\scopes) around as first-class - # objects is convenient. - # # You can define a \scope that applies to all finders using # ActiveRecord::Base.default_scope. - def scoped(options = nil) + def all if current_scope - scope = current_scope.clone + current_scope.clone else scope = relation scope.default_scoped = true scope end + end - scope.merge!(options) if options - scope + def scoped(options = nil) + options ? all.merge!(options) : all end ## |