diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-09 18:33:51 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-11 13:45:08 -0800 |
commit | 42b2e4f85bef64b7aa1382e96c79db1d4f318a56 (patch) | |
tree | 7df93ad2003cb94f014b406ca39266e36d36586d /activerecord/lib/active_record | |
parent | 3b797c8c8681c8f4619bce39d3f042244fe002d9 (diff) | |
download | rails-42b2e4f85bef64b7aa1382e96c79db1d4f318a56.tar.gz rails-42b2e4f85bef64b7aa1382e96c79db1d4f318a56.tar.bz2 rails-42b2e4f85bef64b7aa1382e96c79db1d4f318a56.zip |
We can use the association_proxy method directly in HasOneThroughAssociation now
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 35 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_through_association.rb | 5 |
2 files changed, 20 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 294e1cab50..5fbda0bd3d 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -259,23 +259,6 @@ module ActiveRecord end end - private - # Forwards any missing method call to the \target. - def method_missing(method, *args) - if load_target - unless @target.respond_to?(method) - message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" - raise NoMethodError, message - end - - if block_given? - @target.send(method, *args) { |*block_args| yield(*block_args) } - else - @target.send(method, *args) - end - end - end - # Loads the \target if needed and returns it. # # This method is abstract in the sense that it relies on +find_target+, @@ -299,6 +282,24 @@ module ActiveRecord reset end + private + + # Forwards any missing method call to the \target. + def method_missing(method, *args) + if load_target + unless @target.respond_to?(method) + message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" + raise NoMethodError, message + end + + if block_given? + @target.send(method, *args) { |*block_args| yield(*block_args) } + else + @target.send(method, *args) + end + end + end + # Should be true if there is a foreign key present on the @owner which # references the target. This is used to determine whether we can load # the target if the @owner is currently a new record (and therefore diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb index ab8543e4af..59a704b7bf 100644 --- a/activerecord/lib/active_record/associations/has_one_through_association.rb +++ b/activerecord/lib/active_record/associations/has_one_through_association.rb @@ -13,9 +13,8 @@ module ActiveRecord private def create_through_record(new_value) - proxy = @owner.send(@reflection.through_reflection.name) || - @owner.send(:association_instance_get, @reflection.through_reflection.name) - record = proxy.target + proxy = @owner.send(:association_proxy, @reflection.through_reflection.name) + record = proxy.send(:load_target) if record && !new_value record.destroy |