diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-10 22:13:21 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-10 22:20:14 +0900 |
commit | 5a593486f5c8a73f2be200a409b0a14dff51790c (patch) | |
tree | 6766f9b10cb7dd780eb1515fd75f4d3aa784d993 /activerecord/lib/active_record/associations/through_association.rb | |
parent | e97221a32d02cb0691760fc1783da74e4c3a371a (diff) | |
download | rails-5a593486f5c8a73f2be200a409b0a14dff51790c.tar.gz rails-5a593486f5c8a73f2be200a409b0a14dff51790c.tar.bz2 rails-5a593486f5c8a73f2be200a409b0a14dff51790c.zip |
Fix `stale_state` for nested `has_many :through` associations
Need reloading when through record has replaced.
Diffstat (limited to 'activerecord/lib/active_record/associations/through_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index 806397f83a..54673b74f7 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -4,9 +4,20 @@ module ActiveRecord module Associations # = Active Record Through Association module ThroughAssociation #:nodoc: - delegate :source_reflection, :through_reflection, to: :reflection + delegate :source_reflection, to: :reflection private + def through_reflection + @through_reflection ||= begin + refl = reflection.through_reflection + + while refl.through_reflection? + refl = refl.through_reflection + end + + refl + end + end # We merge in these scopes for two reasons: # @@ -68,7 +79,7 @@ module ActiveRecord end def foreign_key_present? - through_reflection.belongs_to_or_through? && !owner[through_reflection.foreign_key].nil? + through_reflection.belongs_to? && !owner[through_reflection.foreign_key].nil? end def ensure_mutable |