How to load fixtures in order

Is there a way to load the fixtures via another method other than what
Im doing below?

rake db:fixtures:load
FIXTURES=companies,departments,employees,employee_details,phones,addresses

Jadeler Amin wrote:

Is there a way to load the fixtures via another method other than what
Im doing below?

rake db:fixtures:load
FIXTURES=companies,departments,employees,employee_details,phones,addresses

I too need loading fixtures in specific order due to foreign key
constraints. So
I added a list to config/database.yml :

all_fixtures_load_order:

  • :table1
  • :table2

and wrote a rake task to load them:

namespace :db do
namespace :fixtures do
desc “Load all fixtures in particular order to satisfy FK
dependencies”
task :load_all => :environment do
require ‘active_record/fixtures’
ActiveRecord::Base.establish_connection
Fixtures.create_fixtures(‘test/fixtures’, FIXTURES =
ActiveRecord::Base.configurations[“all_fixtures_load_order”])
end unless :environment == ‘production’ # don’t load fixtures in
production
end
end

Hope this helps.

Sava C.