rroblak / seed_dump

Rails 4/5 task to dump your data to db/seeds.rb
MIT License
1.39k stars 225 forks source link

Breaks validations for associations #78

Open jkopczyn opened 9 years ago

jkopczyn commented 9 years ago

I've got a database with Games, Ratings, and Users, and naturally the Ratings validate that both their User and their Game exist. By default, the seed dump breaks this by putting everything into the file in alphabetical order. Could you add an option for specifying order?

yuft commented 9 years ago

I got the same question, hopefully this can be fixed. thank you.

hut8 commented 9 years ago

Instead of specifying order, you could skip the validations. This seems like a tricky problem because of circular dependencies, especially if you have a presence validator that's dependent on a certain condition. https://github.com/werkshy/seed_dump/commit/96c98fe3ab71bdff7fd056864253d61d9de37010 This introduces what you would need for that, at least.

jkopczyn commented 9 years ago

I could do that, but it would be dumb, because I do actually need the objects to be valid.

shadowbq commented 8 years ago

I would like an option like this too. :+1:

SeedDump.dump(order: [User, Comment, Post])
shadowbq commented 8 years ago

You can force a dump order by being explicit in the ENV['MODELS']. It just will not handle missing models or splats.

task :dump => :environment do
    ENV['MODELS'] ||= "Product, Contact, ProductVersion, Owner"
    SeedDump.dump_using_environment(ENV)
end
GarthSnyder commented 8 years ago

I believe this is the same issue as #83. Pull request submitted.