aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-24 20:57:11 +0000
committerJon Leighton <j@jonathanleighton.com>2011-01-30 11:56:41 +0000
commitaa86420be24d7df9c07379bcf6f33904d0d41adc (patch)
tree1ca85cc227bafdeda80e2ed234d26cbe2fa21ce5 /activerecord
parentde05e2fb15ee4fd521aae202eb4517ae05114c28 (diff)
downloadrails-aa86420be24d7df9c07379bcf6f33904d0d41adc.tar.gz
rails-aa86420be24d7df9c07379bcf6f33904d0d41adc.tar.bz2
rails-aa86420be24d7df9c07379bcf6f33904d0d41adc.zip
Rename AssociationProxy#loaded to loaded! as it mutates the association
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/association_preload.rb6
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb2
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb6
-rw-r--r--activerecord/lib/active_record/associations/class_methods/join_dependency.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rw-r--r--activerecord/lib/active_record/autosave_association.rb2
6 files changed, 10 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index cba4bab3ef..b83c00e9f8 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -125,7 +125,7 @@ module ActiveRecord
def add_preloaded_records_to_collection(parent_records, reflection_name, associated_record)
parent_records.each do |parent_record|
association_proxy = parent_record.send(reflection_name)
- association_proxy.loaded
+ association_proxy.loaded!
association_proxy.target.concat(Array.wrap(associated_record))
association_proxy.send(:set_inverse_instance, associated_record)
end
@@ -187,7 +187,7 @@ module ActiveRecord
id_to_record_map = construct_id_map(records)
- records.each {|record| record.send(reflection.name).loaded}
+ records.each { |record| record.send(reflection.name).loaded! }
options = reflection.options
right = Arel::Table.new(options[:join_table]).alias('t0')
@@ -268,7 +268,7 @@ module ActiveRecord
foreign_key = reflection.through_reflection_foreign_key
id_to_record_map = construct_id_map(records, foreign_key || reflection.options[:primary_key])
- records.each {|record| record.send(reflection.name).loaded}
+ records.each { |record| record.send(reflection.name).loaded! }
if options[:through]
through_records = preload_through_records(records, reflection, options[:through])
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 95526be82f..50c69abefb 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -371,7 +371,7 @@ module ActiveRecord
@target = merge_target_lists(targets, @target)
end
- loaded
+ loaded!
target
end
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index ead2c5ede2..8e16246e80 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -128,7 +128,7 @@ module ActiveRecord
end
# Asserts the \target has been loaded setting the \loaded flag to +true+.
- def loaded
+ def loaded!
@loaded = true
@stale_state = stale_state
end
@@ -152,7 +152,7 @@ module ActiveRecord
# Sets the target of this proxy to <tt>\target</tt>, and the \loaded flag to +true+.
def target=(target)
@target = target
- loaded
+ loaded!
end
# Forwards the call to the target. Loads the \target if needed.
@@ -227,7 +227,7 @@ module ActiveRecord
# not reraised. The proxy is \reset and +nil+ is the return value.
def load_target
@target = find_target if find_target?
- loaded
+ loaded!
target
rescue ActiveRecord::RecordNotFound
reset
diff --git a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
index cb3edafab1..fdd4fe8946 100644
--- a/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/class_methods/join_dependency.rb
@@ -210,7 +210,7 @@ module ActiveRecord
case macro
when :has_many, :has_and_belongs_to_many
collection = record.send(join_part.reflection.name)
- collection.loaded
+ collection.loaded!
collection.target.push(association)
collection.send(:set_inverse_instance, association)
when :belongs_to
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 002e1a9ae8..caefd14ee3 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -40,7 +40,7 @@ module ActiveRecord
# If there's nothing in the database and @target has no new records
# we are certain the current target is an empty array. This is a
# documented side-effect of the method that may avoid an extra SELECT.
- @target ||= [] and loaded if count == 0
+ @target ||= [] and loaded! if count == 0
[@reflection.options[:limit], count].compact.min
end
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 70ed16eeaf..9c7bb67479 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -368,7 +368,7 @@ module ActiveRecord
if association.updated?
association_id = association.send(reflection.options[:primary_key] || :id)
self[reflection.foreign_key] = association_id
- association.loaded
+ association.loaded!
end
saved if autosave