Skip to content

Commit 25f2341

Browse files
committed
Move find_target to more correct place for disable joins
Instead of redefining this in has_one_association we can define this in singular association and reuse the existing `find_target` method.
1 parent acee501 commit 25f2341

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

activerecord/lib/active_record/associations/has_one_through_association.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ module Associations
66
class HasOneThroughAssociation < HasOneAssociation #:nodoc:
77
include ThroughAssociation
88

9-
def find_target
10-
return scope.first if disable_joins
11-
12-
super
13-
end
14-
159
private
1610
def replace(record, save = true)
1711
create_through_record(record, save)

activerecord/lib/active_record/associations/singular_association.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def scope_for_create
3838
end
3939

4040
def find_target
41-
super.first
41+
if disable_joins
42+
scope.first
43+
else
44+
super.first
45+
end
4246
end
4347

4448
def replace(record)

0 commit comments

Comments
 (0)