This project is archived and is in readonly mode.
Changeset [bd1666ad1de88598ed6f04ceffb8488a77be4385] by José Valim
June 29th, 2010 @ 04:18 PM
Add scoping and unscoped as the syntax to replace the old with_scope and with_exclusive_scope. A few examples:
- with_scope now should be scoping:
Before:
Comment.with_scope(:find => { :conditions => { :post_id => 1 } }) do
Comment.first #=> SELECT * FROM comments WHERE post_id = 1
end
After:
Comment.where(:post_id => 1).scoping do
Comment.first #=> SELECT * FROM comments WHERE post_id = 1
end
- with_exclusive_scope now should be unscoped:
class Post < ActiveRecord::Base
default_scope :published => true
end
Post.all #=> SELECT * FROM posts WHERE published = true
Before:
Post.with_exclusive_scope do
Post.all #=> SELECT * FROM posts
end
After:
Post.unscoped do
Post.all #=> SELECT * FROM posts
end
Notice you can also use unscoped without a block and it will return an anonymous scope with default_scope values:
Post.unscoped.all #=> SELECT * FROM posts http://github.com/rails/rails/commit/bd1666ad1de88598ed6f04ceffb848...
Committed by José Valim
- A activerecord/test/cases/relation_scoping_test.rb
- M activerecord/lib/active_record/base.rb
- M activerecord/lib/active_record/named_scope.rb
- M activerecord/lib/active_record/persistence.rb
- M activerecord/lib/active_record/relation.rb
- M activerecord/lib/active_record/relation/query_methods.rb
- M activerecord/test/cases/inheritance_test.rb
- M activerecord/test/cases/method_scoping_test.rb
- M activerecord/test/cases/named_scope_test.rb
- M activerecord/test/cases/relations_test.rb
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>