Permalink
Browse files

Fix :include of has_one with :primary_key option

  • Loading branch information...
1 parent 3825f17 commit 27cfeb7cbcc725c36053833ca8e12cc26357a170 @fcheung fcheung committed with wycats Dec 26, 2008
@@ -195,7 +195,7 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
def preload_has_one_association(records, reflection, preload_options={})
return if records.first.send("loaded_#{reflection.name}?")
- id_to_record_map, ids = construct_id_map(records)
+ id_to_record_map, ids = construct_id_map(records, reflection.options[:primary_key])
options = reflection.options
records.each {|record| record.send("set_#{reflection.name}_target", nil)}
if options[:through]
@@ -803,4 +803,20 @@ def test_include_has_many_using_primary_key
end
end
+ def test_preload_has_one_using_primary_key
+ expected = Firm.find(:first).account_using_primary_key
+ firm = Firm.find :first, :include => :account_using_primary_key
+ assert_no_queries do
+ assert_equal expected, firm.account_using_primary_key
+ end
+ end
+
+ def test_include_has_one_using_primary_key
+ expected = Firm.find(1).account_using_primary_key
+ firm = Firm.find(:all, :include => :account_using_primary_key, :order => 'accounts.id').detect {|f| f.id == 1}
+ assert_no_queries do
+ assert_equal expected, firm.account_using_primary_key
+ end
+ end
+
end

0 comments on commit 27cfeb7

Please sign in to comment.