diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-04 16:39:01 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-04 16:47:35 +0200 |
commit | 92661b0c501a65b7f2d9ac8fbf9743152b8a031b (patch) | |
tree | b49e621c5db5b3ba72a1952577c863193b916e16 /activerecord/lib | |
parent | b9bba555caa95389e97bd7d32472ddc1e429d7c2 (diff) | |
download | rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.tar.gz rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.tar.bz2 rails-92661b0c501a65b7f2d9ac8fbf9743152b8a031b.zip |
Move sandbox to AR and pass the sandbox as a value. This way, other ORMs like Datamapper can also have their own sandboxing in rails console.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/console_sandbox.rb | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 276f674cc3..bae2ded244 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -29,7 +29,8 @@ module ActiveRecord # When loading console, force ActiveRecord::Base to be loaded # to avoid cross references when loading a constant for the # first time. Also, make it output to STDERR. - console do + console do |sandbox| + require "active_record/railties/console_sandbox" if sandbox ActiveRecord::Base.logger = Logger.new(STDERR) end diff --git a/activerecord/lib/active_record/railties/console_sandbox.rb b/activerecord/lib/active_record/railties/console_sandbox.rb new file mode 100644 index 0000000000..65a3d68619 --- /dev/null +++ b/activerecord/lib/active_record/railties/console_sandbox.rb @@ -0,0 +1,6 @@ +ActiveRecord::Base.connection.increment_open_transactions +ActiveRecord::Base.connection.begin_db_transaction +at_exit do + ActiveRecord::Base.connection.rollback_db_transaction + ActiveRecord::Base.connection.decrement_open_transactions +end |