aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2018-09-26 12:35:12 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2018-09-26 12:35:12 -0700
commitb42d246c5d020a46d5964d236eb7f0d857ef01e8 (patch)
treeb4fb19def15c5033483ecebe25d4e762ee1a4dab /activerecord/lib/active_record
parentb50f7ae627a0962efbc1805b603f2d5baa6810d7 (diff)
parent6556898884d636c59baae008e42783b8d3e16440 (diff)
downloadrails-b42d246c5d020a46d5964d236eb7f0d857ef01e8.tar.gz
rails-b42d246c5d020a46d5964d236eb7f0d857ef01e8.tar.bz2
rails-b42d246c5d020a46d5964d236eb7f0d857ef01e8.zip
Merge branch 'master' into eager-url-helpers
* master: Remove force parent loading when counter cache child is created/destroyed Raise an error when loading all fixtures from nil fixture_path Revert "Remove `counter_cache_target` which is no longer called" Update counter cache in memory if parent target is existed If association is a hash-like object preloading fails Use the same option for create database statements between Raketask and travis.rb Fix "warning: shadowing outer local variable - config" Remove `counter_cache_target` which is no longer called Fix more offences Change the empty block style to have space inside of the block Fix a content_for test description Stringify database configurations Improve error message when assign wrong attributes to model
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb13
-rw-r--r--activerecord/lib/active_record/associations/preloader.rb7
-rw-r--r--activerecord/lib/active_record/counter_cache.rb8
-rw-r--r--activerecord/lib/active_record/database_configurations.rb4
-rw-r--r--activerecord/lib/active_record/fixtures.rb1
5 files changed, 11 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index da4cc343eb..374247ffec 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -31,24 +31,17 @@ module ActiveRecord::Associations::Builder # :nodoc:
mixin.class_eval do
def belongs_to_counter_cache_after_update(reflection)
- foreign_key = reflection.foreign_key
- cache_column = reflection.counter_cache_column
-
if association(reflection.name).target_changed?
if reflection.polymorphic?
- model = attribute_in_database(reflection.foreign_type).try(:constantize)
model_was = attribute_before_last_save(reflection.foreign_type).try(:constantize)
else
- model = reflection.klass
model_was = reflection.klass
end
- foreign_key_was = attribute_before_last_save foreign_key
- foreign_key = attribute_in_database foreign_key
+ foreign_key_was = attribute_before_last_save(reflection.foreign_key)
+ cache_column = reflection.counter_cache_column
- if foreign_key && model < ActiveRecord::Base
- counter_cache_target(reflection, model, foreign_key).update_counters(cache_column => 1)
- end
+ association(reflection.name).increment_counters
if foreign_key_was && model_was < ActiveRecord::Base
counter_cache_target(reflection, model_was, foreign_key_was).update_counters(cache_column => -1)
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb
index d4d1b2a282..a8f94b574d 100644
--- a/activerecord/lib/active_record/associations/preloader.rb
+++ b/activerecord/lib/active_record/associations/preloader.rb
@@ -98,12 +98,11 @@ module ActiveRecord
# Loads all the given data into +records+ for the +association+.
def preloaders_on(association, records, scope, polymorphic_parent = false)
- case association
- when Hash
+ if association.respond_to?(:to_hash)
preloaders_for_hash(association, records, scope, polymorphic_parent)
- when Symbol
+ elsif association.is_a?(Symbol)
preloaders_for_one(association, records, scope, polymorphic_parent)
- when String
+ elsif association.respond_to?(:to_str)
preloaders_for_one(association.to_sym, records, scope, polymorphic_parent)
else
raise ArgumentError, "#{association.inspect} was not recognized for preload"
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index aad30b40ea..27c1b7a311 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -163,9 +163,7 @@ module ActiveRecord
id = super
each_counter_cached_associations do |association|
- if send(association.reflection.name)
- association.increment_counters
- end
+ association.increment_counters
end
id
@@ -178,9 +176,7 @@ module ActiveRecord
each_counter_cached_associations do |association|
foreign_key = association.reflection.foreign_key.to_sym
unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key
- if send(association.reflection.name)
- association.decrement_counters
- end
+ association.decrement_counters
end
end
end
diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb
index 9ff63c6e10..fa1589511e 100644
--- a/activerecord/lib/active_record/database_configurations.rb
+++ b/activerecord/lib/active_record/database_configurations.rb
@@ -104,7 +104,7 @@ module ActiveRecord
return configs.configurations if configs.is_a?(DatabaseConfigurations)
build_db_config = configs.each_pair.flat_map do |env_name, config|
- walk_configs(env_name, "primary", config)
+ walk_configs(env_name.to_s, "primary", config)
end.compact
if url = ENV["DATABASE_URL"]
@@ -119,7 +119,7 @@ module ActiveRecord
when String
build_db_config_from_string(env_name, spec_name, config)
when Hash
- build_db_config_from_hash(env_name, spec_name, config)
+ build_db_config_from_hash(env_name, spec_name, config.stringify_keys)
end
end
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 6e0f1a0dfb..0d1fdcfb28 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -892,6 +892,7 @@ module ActiveRecord
def fixtures(*fixture_set_names)
if fixture_set_names.first == :all
+ raise StandardError, "No fixture path found. Please set `#{self}.fixture_path`." if fixture_path.blank?
fixture_set_names = Dir["#{fixture_path}/{**,*}/*.{yml}"].uniq
fixture_set_names.map! { |f| f[(fixture_path.to_s.size + 1)..-5] }
else