aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb1
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb3
-rw-r--r--activerecord/lib/active_record/autosave_association.rb14
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb57
5 files changed, 17 insertions, 60 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5b0ba86308..284ae6695b 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -2,6 +2,7 @@ require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/string/conversions'
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 0dfd966466..d9903243ce 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -411,7 +411,8 @@ module ActiveRecord
end
elsif @reflection.klass.scopes[method]
@_named_scopes_cache ||= {}
- @_named_scopes_cache[method] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) }
+ @_named_scopes_cache[method] ||= {}
+ @_named_scopes_cache[method][args] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) }
else
with_scope(construct_scope) do
if block_given?
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index c553e95bad..0dcadfab5f 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
# AutosaveAssociation is a module that takes care of automatically saving
# your associations when the parent is saved. In addition to saving, it
@@ -238,16 +240,10 @@ module ActiveRecord
# go through nested autosave associations that are loaded in memory (without loading
# any new ones), and return true if is changed for autosave
def nested_records_changed_for_autosave?
- self.class.reflect_on_all_autosave_associations.each do |reflection|
- if association = association_instance_get(reflection.name)
- if [:belongs_to, :has_one].include?(reflection.macro)
- return true if association.target && association.target.changed_for_autosave?
- else
- association.target.each {|record| return true if record.changed_for_autosave? }
- end
- end
+ self.class.reflect_on_all_autosave_associations.any? do |reflection|
+ association = association_instance_get(reflection.name)
+ association && Array.wrap(association.target).any?(&:changed_for_autosave?)
end
- false
end
# Validate the association if <tt>:validate</tt> or <tt>:autosave</tt> is
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index bf8c546d2e..454d3e60e3 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -211,7 +211,7 @@ module ActiveRecord
# calling +checkout+ on this pool.
def checkin(conn)
@connection_mutex.synchronize do
- conn.run_callbacks :checkin do
+ conn.send(:_run_checkin_callbacks) do
@checked_out.delete conn
@queue.signal
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index ec25bbf18e..7c7bc5e292 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -3,48 +3,6 @@ require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/object/blank'
require 'set'
-module MysqlCompat #:nodoc:
- # add all_hashes method to standard mysql-c bindings or pure ruby version
- def self.define_all_hashes_method!
- raise 'Mysql not loaded' unless defined?(::Mysql)
-
- target = defined?(Mysql::Result) ? Mysql::Result : MysqlRes
- return if target.instance_methods.include?('all_hashes') ||
- target.instance_methods.include?(:all_hashes)
-
- # Ruby driver has a version string and returns null values in each_hash
- # C driver >= 2.7 returns null values in each_hash
- if Mysql.const_defined?(:VERSION) && (Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700)
- target.class_eval <<-'end_eval', __FILE__, __LINE__ + 1
- def all_hashes # def all_hashes
- rows = [] # rows = []
- each_hash { |row| rows << row } # each_hash { |row| rows << row }
- rows # rows
- end # end
- end_eval
-
- # adapters before 2.7 don't have a version constant
- # and don't return null values in each_hash
- else
- target.class_eval <<-'end_eval', __FILE__, __LINE__ + 1
- def all_hashes # def all_hashes
- rows = [] # rows = []
- all_fields = fetch_fields.inject({}) { |fields, f| # all_fields = fetch_fields.inject({}) { |fields, f|
- fields[f.name] = nil; fields # fields[f.name] = nil; fields
- } # }
- each_hash { |row| rows << all_fields.dup.update(row) } # each_hash { |row| rows << all_fields.dup.update(row) }
- rows # rows
- end # end
- end_eval
- end
-
- unless target.instance_methods.include?('all_hashes') ||
- target.instance_methods.include?(:all_hashes)
- raise "Failed to defined #{target.name}#all_hashes method. Mysql::VERSION = #{Mysql::VERSION.inspect}"
- end
- end
-end
-
module ActiveRecord
class Base
# Establishes a connection to the database that's used by all Active Record objects.
@@ -57,17 +15,17 @@ module ActiveRecord
password = config[:password].to_s
database = config[:database]
- # Require the MySQL driver and define Mysql::Result.all_hashes
unless defined? Mysql
begin
- require_library_or_gem('mysql')
+ require 'mysql'
rescue LoadError
- $stderr.puts '!!! Please install the mysql gem and try again: gem install mysql.'
- raise
+ raise "!!! Missing the mysql gem. Add it to your Gemfile: gem 'mysql', '2.8.1'"
end
- end
- MysqlCompat.define_all_hashes_method!
+ unless defined?(Mysql::Result) && Mysql::Result.method_defined?(:each_hash)
+ raise "!!! Outdated mysql gem. Upgrade to 2.8.1 or later. In your Gemfile: gem 'mysql', '2.8.1'"
+ end
+ end
mysql = Mysql.init
mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslca] || config[:sslkey]
@@ -656,7 +614,8 @@ module ActiveRecord
def select(sql, name = nil)
@connection.query_with_result = true
result = execute(sql, name)
- rows = result.all_hashes
+ rows = []
+ result.each_hash { |row| rows << row }
result.free
rows
end