Revert "Merge pull request #14544 from jefflai2/named_scope_sti"

This reverts commit 9a1abedcde, reversing
changes made to c72d6c91a7.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/models/comment.rb

This change break integration with activerecord-deprecated_finders so
I'm reverting until we find a way to make it work with this gem.
This commit is contained in:
Rafael Mendonça França 2014-05-21 12:15:57 -03:00
parent 1a6b25574f
commit 6931bed1b4
8 changed files with 5 additions and 42 deletions

View File

@ -4,17 +4,6 @@
*Lauro Caetano*
* Changed scoped blocks to be executed with `instance_eval`
Named scopes (i.e. using STI) were previously cached according to
base class so scoped queries made by classes with a common ancestor would
leak. Changed the way scope blocks were called so inheritance rules are
followed during the call and scopes are cached correctly.
Fixes #13466.
*Jefferson Lai*
* Change belongs_to touch to be consistent with timestamp updates
If a model is set up with a belongs_to: touch relatinoship the parent

View File

@ -11,11 +11,11 @@ module ActiveRecord
module ClassMethods
def current_scope #:nodoc:
ScopeRegistry.value_for(:current_scope, self.to_s)
ScopeRegistry.value_for(:current_scope, base_class.to_s)
end
def current_scope=(scope) #:nodoc:
ScopeRegistry.set_value_for(:current_scope, self.to_s, scope)
ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
end
end

View File

@ -148,13 +148,9 @@ module ActiveRecord
extension = Module.new(&block) if block
singleton_class.send(:define_method, name) do |*args|
if body.respond_to?(:to_proc)
scope = all.scoping { instance_exec(*args, &body) }
else
# Body is given as an object instead of a block, so invoke call()
scope = all.scoping { body.call(*args) }
end
scope = all.scoping { body.call(*args) }
scope = scope.extending(extension) if extension
scope || all
end
end

View File

@ -2,13 +2,12 @@ require "cases/helper"
require 'models/post'
require 'models/topic'
require 'models/comment'
require 'models/rating'
require 'models/reply'
require 'models/author'
require 'models/developer'
class NamedScopingTest < ActiveRecord::TestCase
fixtures :posts, :authors, :topics, :comments, :author_addresses, :ratings
fixtures :posts, :authors, :topics, :comments, :author_addresses
def test_implements_enumerable
assert !Topic.all.empty?
@ -116,10 +115,6 @@ class NamedScopingTest < ActiveRecord::TestCase
assert_equal 1,SpecialPost.containing_the_letter_a.count
end
def test_scope_subquery_with_STI
assert_nothing_raised { VerySpecialComment.special_parent(SpecialRating.first).count }
end
def test_has_many_through_associations_have_access_to_scopes
assert_not_equal Comment.containing_the_letter_e, authors(:david).comments
assert !Comment.containing_the_letter_e.empty?

View File

@ -2,23 +2,13 @@ normal_comment_rating:
id: 1
comment_id: 8
value: 1
type: Rating
special_comment_rating:
id: 2
comment_id: 6
value: 1
type: Rating
sub_special_comment_rating:
id: 3
comment_id: 12
value: 1
type: Rating
special_rating:
id: 4
comment_id: 10
value: 1
type: SpecialRating
special_comment_id: 3

View File

@ -42,7 +42,6 @@ class SubSpecialComment < SpecialComment
end
class VerySpecialComment < Comment
scope :special_parent, ->(special_rating) { where parent_id: special_rating.special_comment.id }
end
class CommentThatAutomaticallyAltersPostBody < Comment

View File

@ -2,7 +2,3 @@ class Rating < ActiveRecord::Base
belongs_to :comment
has_many :taggings, :as => :taggable
end
class SpecialRating < Rating
belongs_to :special_comment
end

View File

@ -598,9 +598,7 @@ ActiveRecord::Schema.define do
create_table :ratings, force: true do |t|
t.integer :comment_id
t.integer :special_comment_id
t.integer :value
t.string :type
end
create_table :readers, force: true do |t|