1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix fixtures not loading if a belongs_to association is defined with a :foreign_key option that's a symbol

This commit is contained in:
Will Bryant 2014-09-08 23:32:42 +12:00 committed by Arthur Neves
parent 4dfbfc7c27
commit 2a1b45af56
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
2 changed files with 10 additions and 1 deletions

View file

@ -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

View file

@ -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