diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-26 22:46:11 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-11-26 22:46:11 +0000 |
commit | c7e39691899b080a451a4c94a3632cada5ab0750 (patch) | |
tree | a8f4726cb92225a0bf7517ea666e3b644cd1cb1c /activerecord/lib/active_record | |
parent | 8b3f83105ce719642a8f079f72c4f03c97cfc321 (diff) | |
download | rails-c7e39691899b080a451a4c94a3632cada5ab0750.tar.gz rails-c7e39691899b080a451a4c94a3632cada5ab0750.tar.bz2 rails-c7e39691899b080a451a4c94a3632cada5ab0750.zip |
Foxy fixtures: support single-table inheritance. Closes #10234.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8219 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 05c0aa0e39..40fbadc233 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -581,7 +581,15 @@ class Fixtures < YAML::Omap row[primary_key_name] = Fixtures.identify(label) end - model_class.reflect_on_all_associations.each do |association| + # If STI is used, find the correct subclass for association reflection + reflection_class = + if row.include?(inheritance_column_name) + row[inheritance_column_name].constantize rescue model_class + else + model_class + end + + reflection_class.reflect_on_all_associations.each do |association| case association.macro when :belongs_to # Do not replace association name with association foreign key if they are named the same @@ -650,6 +658,10 @@ class Fixtures < YAML::Omap end end + def inheritance_column_name + @inheritance_column_name ||= model_class && model_class.inheritance_column + end + def column_names @column_names ||= @connection.columns(@table_name).collect(&:name) end |