diff options
author | Ernie Miller <ernie@metautonomo.us> | 2010-03-29 16:38:44 -0400 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-03-29 15:24:27 -0700 |
commit | 63026541b209cc11ffd74cf3ca04b89d1e437737 (patch) | |
tree | 6f274f2d13577e64f03160fc788b705c9893f85e /activerecord/test | |
parent | a509b0b18fd02d1d712248ce94e1d36750d58565 (diff) | |
download | rails-63026541b209cc11ffd74cf3ca04b89d1e437737.tar.gz rails-63026541b209cc11ffd74cf3ca04b89d1e437737.tar.bz2 rails-63026541b209cc11ffd74cf3ca04b89d1e437737.zip |
Fix honoring :primary_key option when joining or eager loading a belongs_to association
[#765 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 163ac025dd..c57760d658 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -32,6 +32,12 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal companies(:first_firm).name, client.firm_with_primary_key.name end + def test_belongs_to_with_primary_key_joins_on_correct_column + sql = Client.joins(:firm_with_primary_key).to_sql + assert_no_match /"firm_with_primary_keys_companies"\."id"/, sql + assert_match /"firm_with_primary_keys_companies"\."name"/, sql + end + def test_proxy_assignment account = Account.find(1) assert_nothing_raised { account.firm = account.firm } @@ -61,6 +67,13 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal apple.name, citibank.firm_name end + def test_eager_loading_with_primary_key + apple = Firm.create("name" => "Apple") + citibank = Client.create("name" => "Citibank", :firm_name => "Apple") + citibank_result = Client.find(:first, :conditions => {:name => "Citibank"}, :include => :firm_with_primary_key) + assert_not_nil citibank_result.instance_variable_get("@firm_with_primary_key") + end + def test_no_unexpected_aliasing first_firm = companies(:first_firm) another_firm = companies(:another_firm) |