diff options
author | Will Bryant <will.bryant@gmail.com> | 2014-09-08 23:32:42 +1200 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2014-09-22 13:10:55 -0400 |
commit | 2a1b45af56d6c0ec39941c50ff98bf2e6d74d274 (patch) | |
tree | f69bae4e6dee2c28d04680c2a63b0712b520ad96 | |
parent | 4dfbfc7c27085ec9118522c9298e51d9918c7895 (diff) | |
download | rails-2a1b45af56d6c0ec39941c50ff98bf2e6d74d274.tar.gz rails-2a1b45af56d6c0ec39941c50ff98bf2e6d74d274.tar.bz2 rails-2a1b45af56d6c0ec39941c50ff98bf2e6d74d274.zip |
fix fixtures not loading if a belongs_to association is defined with a :foreign_key option that's a symbol
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 1724fa893d..4044f5f7b2 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -661,7 +661,7 @@ module ActiveRecord row[association.foreign_type] = $1 end - fk_type = association.active_record.columns_hash[association.foreign_key].type + fk_type = association.active_record.columns_hash[fk_name].type row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type) end when :has_many diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 385ec48005..e96f6cb67a 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -810,6 +810,15 @@ class FoxyFixturesTest < ActiveRecord::TestCase assert admin_accounts(:signals37).users.include?(admin_users(:david)) assert_equal 2, admin_accounts(:signals37).users.size end + + class Nemesis < ActiveRecord::Base + self.table_name = "mateys" + belongs_to :mortal_enemy, :class_name => 'Pirate', :foreign_key => :target_id + end + + def test_symbol_foreign_key_id + ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, "nemeses", "nemeses" => Nemesis) + end end class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase |