From ba647e53c910b84f9e7aa572eb22c011beafdf79 Mon Sep 17 00:00:00 2001 From: Alexey Ilyichev Date: Fri, 22 Oct 2010 18:03:14 +0400 Subject: [PATCH] Made has_one :through on new record query for associated object --- .../associations/has_one_through_association.rb | 7 +++++-- .../has_one_through_associations_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 2 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 fba0a2b..47765cf 100644 --- a/activerecord/lib/active_record/associations/has_one_through_association.rb +++ b/activerecord/lib/active_record/associations/has_one_through_association.rb @@ -11,7 +11,7 @@ module ActiveRecord @target = new_value end - private + private def create_through_record(new_value) #nodoc: klass = @reflection.through_reflection.klass @@ -31,10 +31,13 @@ module ActiveRecord end end - private def find_target with_scope(construct_scope) { @reflection.klass.find(:first) } end + + def foreign_key_present + true + end end end end diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb index 5d15314..24d4a82 100644 --- a/activerecord/test/cases/associations/has_one_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb @@ -212,4 +212,9 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase minivan.dashboard end end + + def test_has_one_through_returns_associated_object_for_new_record + member_detail = @member.build_member_detail + assert_equal @member.member_type, member_detail.member_type + end end -- 1.7.0.4