aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb29
-rwxr-xr-xactiverecord/test/associations_test.rb7
2 files changed, 22 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 1e4414cfe3..ed1dd36f75 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -12,15 +12,15 @@ module ActiveRecord
Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
reset
end
-
+
def proxy_owner
@owner
end
-
+
def proxy_reflection
@reflection
end
-
+
def proxy_target
@target
end
@@ -28,23 +28,23 @@ module ActiveRecord
def respond_to?(symbol, include_priv = false)
proxy_respond_to?(symbol, include_priv) || (load_target && @target.respond_to?(symbol, include_priv))
end
-
+
# Explicitly proxy === because the instance method removal above
# doesn't catch it.
def ===(other)
load_target
other === @target
end
-
+
def aliased_table_name
@reflection.klass.table_name
end
-
+
def conditions
@conditions ||= interpolate_sql(sanitize_sql(@reflection.options[:conditions])) if @reflection.options[:conditions]
end
alias :sql_conditions :conditions
-
+
def reset
@loaded = false
@target = nil
@@ -53,25 +53,26 @@ module ActiveRecord
def reload
reset
load_target
+ self unless @target.nil?
end
def loaded?
@loaded
end
-
+
def loaded
@loaded = true
end
-
+
def target
@target
end
-
+
def target=(target)
@target = target
loaded
end
-
+
def inspect
reload unless loaded?
@target.inspect
@@ -81,7 +82,7 @@ module ActiveRecord
def dependent?
@reflection.options[:dependent]
end
-
+
def quoted_record_ids(records)
records.map { |record| record.quoted_id }.join(',')
end
@@ -117,10 +118,10 @@ module ActiveRecord
:select => @reflection.options[:select]
)
end
-
+
private
def method_missing(method, *args, &block)
- if load_target
+ if load_target
@target.send(method, *args, &block)
end
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 42e3e09187..64dc34066a 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -133,6 +133,13 @@ class AssociationProxyTest < Test::Unit::TestCase
assert_nil p.author.reset
end
+ def test_reload_returns_assocition
+ david = developers(:david)
+ assert_nothing_raised do
+ assert_equal david.projects, david.projects.reload.reload
+ end
+ end
+
def setup_dangling_association
josh = Author.create(:name => "Josh")
p = Post.create(:title => "New on Edge", :body => "More cool stuff!", :author => josh)