aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_one_through_association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/has_one_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_one_through_association.rb22
1 files changed, 12 insertions, 10 deletions
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 d93c8e7852..830aa1808a 100644
--- a/activerecord/lib/active_record/associations/has_one_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_through_association.rb
@@ -1,6 +1,16 @@
+require "active_record/associations/through_association_scope"
+
module ActiveRecord
module Associations
- class HasOneThroughAssociation < HasManyThroughAssociation
+ class HasOneThroughAssociation < HasOneAssociation
+ include ThroughAssociationScope
+
+ def replace(new_value)
+ create_through_record(new_value)
+ @target = new_value
+ end
+
+ private
def create_through_record(new_value) #nodoc:
klass = @reflection.through_reflection.klass
@@ -15,16 +25,8 @@ module ActiveRecord
end
private
- def find(*args)
- super(args.merge(:limit => 1))
- end
-
def find_target
- super.first
- end
-
- def reset_target!
- @target = nil
+ with_scope(construct_scope) { @reflection.klass.find(:first) }
end
end
end