aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-14 12:17:40 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-14 12:17:40 -0300
commit25649c7fd74219881342b2cb59f97c08f646a4ea (patch)
treec115a57a3aab8c354ca58764416990131d61dd6c /activerecord/lib/active_record/associations/association.rb
parentc05f9558eebf88a137d606c27f3e0be232e35100 (diff)
parent04e3b41e2fc834c842ef50f25feea829aab0bbbc (diff)
downloadrails-25649c7fd74219881342b2cb59f97c08f646a4ea.tar.gz
rails-25649c7fd74219881342b2cb59f97c08f646a4ea.tar.bz2
rails-25649c7fd74219881342b2cb59f97c08f646a4ea.zip
Merge pull request #9499 from dmitry/inverse_instance_should_not_be_reloaded_after_stale_state_change
Inversed instance should not be reloaded after stale state was changed Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/associations/association.rb')
-rw-r--r--activerecord/lib/active_record/associations/association.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 04c36d5740..e6a45487d0 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -17,6 +17,7 @@ module ActiveRecord
# HasManyThroughAssociation + ThroughAssociation
class Association #:nodoc:
attr_reader :owner, :target, :reflection
+ attr_accessor :inversed
delegate :options, :to => :reflection
@@ -42,6 +43,7 @@ module ActiveRecord
@loaded = false
@target = nil
@stale_state = nil
+ @inversed = false
end
# Reloads the \target and returns +self+ on success.
@@ -59,8 +61,9 @@ module ActiveRecord
# Asserts the \target has been loaded setting the \loaded flag to +true+.
def loaded!
- @loaded = true
+ @loaded = true
@stale_state = stale_state
+ @inversed = false
end
# The target is stale if the target no longer points to the record(s) that the
@@ -70,7 +73,7 @@ module ActiveRecord
#
# Note that if the target has not been loaded, it is not considered stale.
def stale_target?
- loaded? && @stale_state != stale_state
+ !inversed && loaded? && @stale_state != stale_state
end
# Sets the target of this association to <tt>\target</tt>, and the \loaded flag to +true+.
@@ -104,6 +107,7 @@ module ActiveRecord
if record && invertible_for?(record)
inverse = record.association(inverse_reflection_for(record).name)
inverse.target = owner
+ inverse.inversed = true
end
end