Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7785 from okcwest/3-2-stable
backport 68677ff
  • Loading branch information
tenderlove committed Sep 28, 2012
2 parents 8ca05c2 + 8dbf337 commit e1a10b1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 3 additions & 4 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -450,12 +450,12 @@ def arel_engine
private private


def relation #:nodoc: def relation #:nodoc:
@relation ||= Relation.new(self, arel_table) relation = Relation.new(self, arel_table)


if finder_needs_type_condition? if finder_needs_type_condition?
@relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name) relation.where(type_condition).create_with(inheritance_column.to_sym => sti_name)
else else
@relation relation
end end
end end
end end
Expand Down Expand Up @@ -489,7 +489,6 @@ def initialize(attributes = nil, options = {})
@marked_for_destruction = false @marked_for_destruction = false
@previously_changed = {} @previously_changed = {}
@changed_attributes = {} @changed_attributes = {}
@relation = nil


ensure_proper_type ensure_proper_type


Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/scoping/named.rb
Expand Up @@ -34,7 +34,7 @@ def scoped(options = nil)
if current_scope if current_scope
current_scope.clone current_scope.clone
else else
scope = relation.clone scope = relation
scope.default_scoped = true scope.default_scoped = true
scope scope
end end
Expand All @@ -48,7 +48,7 @@ def scope_attributes # :nodoc:
if current_scope if current_scope
current_scope.scope_for_create current_scope.scope_for_create
else else
scope = relation.clone scope = relation
scope.default_scoped = true scope.default_scoped = true
scope.scope_for_create scope.scope_for_create
end end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relation_scoping_test.rb
Expand Up @@ -548,4 +548,8 @@ def test_default_scope_is_threadsafe
end end
threads.each(&:join) threads.each(&:join)
end end

def test_default_scope_unscoped_is_not_cached
assert_not_equal DeveloperCalledDavid.unscoped.object_id, DeveloperCalledDavid.unscoped.object_id
end
end end
4 changes: 4 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -1093,6 +1093,10 @@ def test_unscoped_block_style
assert_equal 'honda', FastCar.unscoped { FastCar.order_using_old_style.limit(1).first.name} assert_equal 'honda', FastCar.unscoped { FastCar.order_using_old_style.limit(1).first.name}
end end


def test_unscoped_relation_clones
assert_not_equal CoolCar.unscoped.object_id, CoolCar.unscoped.object_id
end

def test_intersection_with_array def test_intersection_with_array
relation = Author.where(:name => "David") relation = Author.where(:name => "David")
rails_author = relation.first rails_author = relation.first
Expand Down

0 comments on commit e1a10b1

Please sign in to comment.