diff --git a/lib/generators/hoardable/migration_generator.rb b/lib/generators/hoardable/migration_generator.rb index 8688189..6b2d39b 100644 --- a/lib/generators/hoardable/migration_generator.rb +++ b/lib/generators/hoardable/migration_generator.rb @@ -37,6 +37,12 @@ def create_triggers end no_tasks do + def table_name + class_name.singularize.constantize.table_name + rescue StandardError + super + end + def foreign_key_type options[:foreign_key_type] || class_name.singularize.constantize.columns.find { |col| col.name == primary_key }.sql_type diff --git a/test/test_migration_generator.rb b/test/test_migration_generator.rb index 7fd685a..23691e7 100644 --- a/test/test_migration_generator.rb +++ b/test/test_migration_generator.rb @@ -38,6 +38,11 @@ def shared_book_assertions(foreign_key_type = "uuid") shared_post_assertions end + it "supports using a model with a custom table_name" do + run_generator ["Hoardable::Post"] + shared_post_assertions + end + it "generates book migration with pluralized resource" do run_generator ["books"] shared_book_assertions