diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-12-27 19:34:06 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-12-27 19:40:10 +0900 |
commit | 4ae8d6182fd9351b9451003f9380d8855f3f5a94 (patch) | |
tree | fd27f7f97333e3a37fecc4dede110a1022f0646e /activerecord/lib/active_record/associations/singular_association.rb | |
parent | 50d9c06b0177afdad5f3ea657186cedc883c1542 (diff) | |
parent | bc30d421f3782a4ff5ba7751f132c5219d638b3e (diff) | |
download | rails-4ae8d6182fd9351b9451003f9380d8855f3f5a94.tar.gz rails-4ae8d6182fd9351b9451003f9380d8855f3f5a94.tar.bz2 rails-4ae8d6182fd9351b9451003f9380d8855f3f5a94.zip |
Merge pull request #34806 from bogdan/reuse-find-target
Reuse AR::Association#find_target method
Diffstat (limited to 'activerecord/lib/active_record/associations/singular_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/singular_association.rb | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index 8e50cce102..c296f9882e 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -36,19 +36,7 @@ module ActiveRecord end def find_target - scope = self.scope - return scope.take if skip_statement_cache?(scope) - - conn = klass.connection - sc = reflection.association_scope_cache(conn, owner) do |params| - as = AssociationScope.create { params.bind } - target_scope.merge!(as.scope(self)).limit(1) - end - - binds = AssociationScope.get_bind_values(owner, reflection.chain) - sc.execute(binds, conn) do |record| - set_inverse_instance record - end.first + super.first rescue ::RangeError nil end |