aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-06-21 12:58:27 +0000
committerJamis Buck <jamis@37signals.com>2005-06-21 12:58:27 +0000
commit361be5a7dd1d70e55d6b003b987794e94b2f9c1e (patch)
tree5749b77591749af6a12c3a133ce8db11ad04cadb /activerecord/lib
parentc88ce046621b77e6d39ae60edd4996066414801a (diff)
downloadrails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.tar.gz
rails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.tar.bz2
rails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.zip
Removed the AR::Recursion module--it broke more code than it fixed
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1470 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record.rb2
-rw-r--r--activerecord/lib/active_record/recursion.rb60
2 files changed, 0 insertions, 62 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 168719060d..9d821d17e9 100755
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -46,7 +46,6 @@ require 'active_record/acts/tree'
require 'active_record/acts/nested_set'
require 'active_record/locking'
require 'active_record/migration'
-require 'active_record/recursion'
ActiveRecord::Base.class_eval do
include ActiveRecord::Validations
@@ -60,7 +59,6 @@ ActiveRecord::Base.class_eval do
include ActiveRecord::Acts::Tree
include ActiveRecord::Acts::List
include ActiveRecord::Acts::NestedSet
- include ActiveRecord::Recursion # must go last!
end
require 'active_record/connection_adapters/mysql_adapter'
diff --git a/activerecord/lib/active_record/recursion.rb b/activerecord/lib/active_record/recursion.rb
deleted file mode 100644
index 36589238e7..0000000000
--- a/activerecord/lib/active_record/recursion.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-module ActiveRecord
- # Wraps a guard around #save to make sure that recursive calls don't actually
- # invoke save multiple times. Recursive calls to save can occur quite
- # easily, and unintentionally. Consider the following case:
- #
- # class Project < ActiveRecord::Base
- # has_and_belongs_to_many :people
- # after_create :grant_access_to_admins
- #
- # def grant_access_to_admins
- # Person.admins.each do |admin|
- # admin.projects.push_with_attributes(self, "access_level" => 42)
- # end
- # end
- # end
- #
- # class Person < ActiveRecord::Base
- # has_and_belongs_to_many :projects
- # ...
- # end
- #
- # teddy = Person.find_by_name("teddy")
- # project = Project.new :name => "sumo wrestling"
- # project.people << teddy
- # project.save!
- #
- # The #push_with_attributes causes +self+ (the project) to be saved again,
- # even though we're already in the midst of doing a save. This results in
- # "teddy" _not_ being added to the project's people list, because the
- # recursive call resets the new-record status and thus ignores any
- # non-new records in the collection.
- #
- # Thus, the need for a recursive guard on save.
- module Recursion
- def self.append_features(base) # :nodoc:
- super
-
- base.class_eval do
- alias_method :save_without_recursive_guard, :save
- alias_method :save, :save_with_recursive_guard
- end
- end
-
- # Wrap the save call with a sentinel that prevents saves from occuring if
- # a save is already in progress.
- def save_with_recursive_guard(*args)
- critical = Thread.critical
- Thread.critical = true
- old_save_state = @currently_saving_record
- return true if @currently_saving_record
- @currently_saving_record = true
- Thread.critical = critical
-
- save_without_recursive_guard(*args)
- ensure
- Thread.critical = critical
- @currently_saving_record = old_save_state
- end
- end
-end