Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Changeset [bd1666ad1de88598ed6f04ceffb8488a77be4385] by José Valim

Revision bd1666ad1de88598ed6f04ceffb8488a77be4385, committed 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...

10 changed files

  • 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