I was trying to deal with foreign key issues related to order of
fixture loading when I came across this:

http://techpolesen.blogspot.com/2007/04/rails-fixture-tips.html

This got me looking deeper into rails and I noticed that
db:fixtures:load calls Fixtures.create_fixtures once for each fixture
file. However, Fixtures.create_fixtures is capable of taking multiple
files and also handle the correct order for both deletes and inserts,
so I created a new rake task that handles deletes/inserts in the
correct order based on ENV['FIXTURES']. I'm just wondering why the
rake task doesn't work this way:

namespace :db do
  namespace :fixtures do
    desc "Load fixtures into the current environment's database.  Load
specific fixtures using FIXTURES=x,y"
    task :load => :environment do
      require 'active_record/fixtures'
      ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
      fixtures = (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) :
Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}')))
      Fixtures.create_fixtures('test/fixtures', fixtures)
    end
  end
end


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to