diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-18 07:52:58 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-18 07:52:58 +0000 |
commit | 03097d3a6047e269641a14f4c93838598011f0b5 (patch) | |
tree | a30a49108dfffc631ee4eb652fce7b41bb4b517e /activerecord/lib/active_record | |
parent | b8c07c0325fdfee701de1a68811c941bced606be (diff) | |
download | rails-03097d3a6047e269641a14f4c93838598011f0b5.tar.gz rails-03097d3a6047e269641a14f4c93838598011f0b5.tar.bz2 rails-03097d3a6047e269641a14f4c93838598011f0b5.zip |
Fixed that fixtures were being deleted in the same order as inserts causing FK errors #890 [andrew.john.peters@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1205 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 100908cafb..50a824987d 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -251,6 +251,8 @@ class Fixtures < Hash end end + attr_reader :table_name + def initialize(connection, table_name, fixture_path, file_filter = DEFAULT_FILTER_RE) @connection, @table_name, @fixture_path, @file_filter = connection, table_name, fixture_path, file_filter @class_name = Inflector.classify(@table_name) @@ -470,30 +472,35 @@ module Test #:nodoc: private def load_fixtures @loaded_fixtures = {} - fixture_table_names.each do |table_name| - @loaded_fixtures[table_name] = Fixtures.create_fixtures(fixture_path, table_name) + fixtures = Fixtures.create_fixtures(fixture_path, fixture_table_names) + unless fixtures.nil? + if fixtures.instance_of?(Fixtures) + @loaded_fixtures[fixtures.table_name] = fixtures + else + fixtures.each { |f| @loaded_fixtures[f.table_name] = f } + end end end - + # for pre_loaded_fixtures, only require the classes once. huge speed improvement @@required_fixture_classes = false - + def instantiate_fixtures if pre_loaded_fixtures raise RuntimeError, 'Load fixtures before instantiating them.' if Fixtures.all_loaded_fixtures.empty? unless @@required_fixture_classes - self.class.require_fixture_classes Fixtures.all_loaded_fixtures.keys + self.class.require_fixture_classes Fixtures.all_loaded_fixtures.keys @@required_fixture_classes = true end Fixtures.instantiate_all_loaded_fixtures(self, load_instances?) - else + else raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil? @loaded_fixtures.each do |table_name, fixtures| Fixtures.instantiate_fixtures(self, table_name, fixtures, load_instances?) end end end - + def load_instances? use_instantiated_fixtures != :no_instances end |