aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-03-16 15:08:38 -0700
committerwycats <wycats@gmail.com>2010-03-16 15:11:00 -0700
commitdf735cf5b712312a161d703f2606b145ea2d3b85 (patch)
tree02339c72a2f31571bde672d00c8f2f37dfc84f67 /activerecord/lib/active_record
parent12bf636461e3aab661119ceb3a104cfb70a11666 (diff)
downloadrails-df735cf5b712312a161d703f2606b145ea2d3b85.tar.gz
rails-df735cf5b712312a161d703f2606b145ea2d3b85.tar.bz2
rails-df735cf5b712312a161d703f2606b145ea2d3b85.zip
fisting uninitialized ivar warnings. [#4198 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/aggregations.rb5
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb1
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb16
3 files changed, 14 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 9ecf231a66..08389907ef 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -213,6 +213,11 @@ module ActiveRecord
module_eval do
define_method(name) do |*args|
force_reload = args.first || false
+
+ unless instance_variable_defined?("@#{name}")
+ instance_variable_set("@#{name}", nil)
+ end
+
if (instance_variable_get("@#{name}").nil? || force_reload) && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? })
attrs = mapping.collect {|pair| read_attribute(pair.first)}
object = case constructor
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 0ff89df1e3..4fb1df3ab9 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -53,6 +53,7 @@ module ActiveRecord
def initialize(owner, reflection)
@owner, @reflection = owner, reflection
+ @updated = false
reflection.check_validity!
Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
reset
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 64e761e7a4..a8698a2f5a 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -18,7 +18,7 @@ module ActiveRecord
def save_with_dirty(*args) #:nodoc:
if status = save_without_dirty(*args)
@previously_changed = changes
- changed_attributes.clear
+ @changed_attributes.clear
end
status
end
@@ -26,8 +26,8 @@ module ActiveRecord
# Attempts to <tt>save!</tt> the record and clears changed attributes if successful.
def save_with_dirty!(*args) #:nodoc:
save_without_dirty!(*args).tap do
- @previously_changed = changes
- changed_attributes.clear
+ @previously_changed = changes
+ @changed_attributes.clear
end
end
@@ -35,7 +35,7 @@ module ActiveRecord
def reload_with_dirty(*args) #:nodoc:
reload_without_dirty(*args).tap do
@previously_changed.clear
- changed_attributes.clear
+ @changed_attributes.clear
end
end
@@ -45,12 +45,12 @@ module ActiveRecord
attr = attr.to_s
# The attribute already has an unsaved change.
- if changed_attributes.include?(attr)
- old = changed_attributes[attr]
- changed_attributes.delete(attr) unless field_changed?(attr, old, value)
+ if attribute_changed?(attr)
+ old = @changed_attributes[attr]
+ @changed_attributes.delete(attr) unless field_changed?(attr, old, value)
else
old = clone_attribute_value(:read_attribute, attr)
- changed_attributes[attr] = old if field_changed?(attr, old, value)
+ @changed_attributes[attr] = old if field_changed?(attr, old, value)
end
# Carry on.