aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDmitry Polushkin <dmitry.polushkin@gmail.com>2013-03-01 01:08:27 +0000
committerDmitry Polushkin <dmitry.polushkin@gmail.com>2013-10-13 21:51:40 +0100
commit05b178085a2ad3bf3f2c0dcd1ea40fb5e8c8dc0d (patch)
treec4d2fb44cff900cd92fe912756b435b8c9d17436 /activerecord/lib/active_record
parentdcff027a5242b20c0c90eb062dddb22ccf51aed9 (diff)
downloadrails-05b178085a2ad3bf3f2c0dcd1ea40fb5e8c8dc0d.tar.gz
rails-05b178085a2ad3bf3f2c0dcd1ea40fb5e8c8dc0d.tar.bz2
rails-05b178085a2ad3bf3f2c0dcd1ea40fb5e8c8dc0d.zip
inversed instance should not be reloaded after stale state was changed
check at association reader that record is inverted and should not be reloaded because of stale was changed at target record
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 04c36d5740..2f33ecb71f 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -42,6 +42,7 @@ module ActiveRecord
@loaded = false
@target = nil
@stale_state = nil
+ @inversed = false
end
# Reloads the \target and returns +self+ on success.
@@ -59,8 +60,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 +72,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 +106,7 @@ module ActiveRecord
if record && invertible_for?(record)
inverse = record.association(inverse_reflection_for(record).name)
inverse.target = owner
+ inverse.instance_variable_set(:@inversed, true)
end
end