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:
parent
4dfbfc7c27
commit
2a1b45af56
2 changed files with 10 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue