mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #4011 from lest/scope-with-lambda-duplicates
call scope within unscoped to prevent duplication of where values
This commit is contained in:
@@ -177,7 +177,7 @@ module ActiveRecord
|
||||
extension = Module.new(&Proc.new) if block_given?
|
||||
|
||||
scope_proc = lambda do |*args|
|
||||
options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options
|
||||
options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options
|
||||
options = scoped.apply_finder_options(options) if options.is_a?(Hash)
|
||||
|
||||
relation = scoped.merge(options)
|
||||
|
||||
@@ -337,6 +337,11 @@ class NamedScopeTest < ActiveRecord::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_duplicates_where_values
|
||||
where_values = Topic.where("1=1").scope_with_lambda.where_values
|
||||
assert_equal ["1=1"], where_values
|
||||
end
|
||||
|
||||
def test_chaining_with_duplicate_joins
|
||||
join = "INNER JOIN comments ON comments.post_id = posts.id"
|
||||
post = Post.find(1)
|
||||
|
||||
@@ -8,6 +8,8 @@ class Topic < ActiveRecord::Base
|
||||
scope :approved, :conditions => {:approved => true}
|
||||
scope :rejected, :conditions => {:approved => false}
|
||||
|
||||
scope :scope_with_lambda, lambda { scoped }
|
||||
|
||||
scope :by_lifo, :conditions => {:author_name => 'lifo'}
|
||||
|
||||
scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}}
|
||||
|
||||
Reference in New Issue
Block a user