From bdd64912ac80818d338c2c7fea224b0b243ac5d4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 22 Apr 2014 10:51:20 -0500 Subject: extract record fetching to a method for belongs_to --- activerecord/lib/active_record/associations/singular_association.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb index 747bb5f1d6..ba28e91633 100644 --- a/activerecord/lib/active_record/associations/singular_association.rb +++ b/activerecord/lib/active_record/associations/singular_association.rb @@ -38,8 +38,12 @@ module ActiveRecord scope.scope_for_create.stringify_keys.except(klass.primary_key) end + def get_records + scope.limit(1).to_a + end + def find_target - if record = scope.take + if record = get_records.first set_inverse_instance record end end -- cgit v1.2.3