seed_dump
seed_dump copied to clipboard
has_and_belongs_to_many support?
Is there a way to get the records of the join tables from a has_and_belongs_to_many
association?
For example, I'd like to get the assemblies_parts
dumped in addition to assemblies
and parts
in the rails example: http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association
+1
is this issue addressed? . Is there any way to get dump of join tables?
Not yet. I haven't had the need/time to add support for HABTM, though I of course would be happy to merge any pull requests that provide support :)
I'm leaving this issue open as I would like to have support for HABTM at some point.
In Rails 4.1, HABTM is now implemented with has_many :through
so this now pretty much works. The only problem is that you get a psuedo-model from both sides of the relationship, so I threw this in a rake task:
# Dedupe models on table name so HABTM tables don't get dumped twice.
Rails.application.eager_load!
ENV['MODELS'] =
ActiveRecord::Base.descendants.
uniq {|c| c.table_name}.
map(&:to_s).
join(',')
Rake::Task['db:seed:dump'].execute
Also see pull request #101. This is essentially the same as mschulkind's solution, but applied automatically, and only to auto-generated HABTM_* models. Is there any case in which you would not want this behavior?
This would be a cool feature!