aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-25 22:58:45 +0900
committerGitHub <noreply@github.com>2017-09-25 22:58:45 +0900
commit70656c44530eb6826b454576c3beb16a91c7cb0f (patch)
treea5d378d9fe9183842d9f44c4d76b55f1c3a77281 /activerecord/lib/active_record
parentab08f33f312c20638b9a7c38ee6318727c7f107d (diff)
parent89711d99b08b5ace8aa5b7394e2ccedb302d118f (diff)
downloadrails-70656c44530eb6826b454576c3beb16a91c7cb0f.tar.gz
rails-70656c44530eb6826b454576c3beb16a91c7cb0f.tar.bz2
rails-70656c44530eb6826b454576c3beb16a91c7cb0f.zip
Merge pull request #30706 from tgxworld/fix_preload_memoization
PERF: Restore memoization when preloading associations.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/reflection.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 82ab2415e1..032df925bf 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -425,7 +425,6 @@ module ActiveRecord
def initialize(name, scope, options, active_record)
super
- @automatic_inverse_of = nil
@type = options[:as] && (options[:foreign_type] || "#{options[:as]}_type")
@foreign_type = options[:foreign_type] || "#{name}_type"
@constructable = calculate_constructable(macro, options)
@@ -609,12 +608,14 @@ module ActiveRecord
# If it cannot find a suitable inverse association name, it returns
# +nil+.
def inverse_name
- options.fetch(:inverse_of) do
- @automatic_inverse_of ||= automatic_inverse_of
+ unless defined?(@inverse_name)
+ @inverse_name = options.fetch(:inverse_of) { automatic_inverse_of }
end
+
+ @inverse_name
end
- # returns either false or the inverse association name that it finds.
+ # returns either +nil+ or the inverse association name that it finds.
def automatic_inverse_of
if can_find_inverse_of_automatically?(self)
inverse_name = ActiveSupport::Inflector.underscore(options[:as] || active_record.name.demodulize).to_sym
@@ -631,8 +632,6 @@ module ActiveRecord
return inverse_name
end
end
-
- false
end
# Checks if the inverse reflection that is returned from the