@@ -31,9 +31,20 @@ def alter_the_model
3131 end
3232
3333 def alter_the_migration
34+ puts "Table name: #{ table_name } "
35+ puts "Namespaced: #{ namespaced? } "
36+ puts "Coreapplication: #{ @in_core_application } "
37+
3438 migration = self . class . migration_exists? ( File . absolute_path ( "db/migrate" ) , "create_#{ table_name } " )
39+
40+ if @in_core_application
41+ gsub_file migration , "create_table :#{ table_name } " , "create_table :#{ unnamespaced_table_name } "
42+ puts "From #{ table_name } to #{ unnamespaced_table_name } "
43+ end
44+
3545 gsub_file migration , "create_table" , "create_content_table"
3646
47+
3748 # Attachments do not require a FK from this model to attachments.
3849 self . attributes . select { |attr | attr . type == :attachment } . each do |attribute |
3950 gsub_file migration , "t.attachment :#{ attribute . name } " , ""
@@ -70,6 +81,14 @@ def create_routes
7081
7182 private
7283
84+ # @override NamedBase#table_name Copy&Paste of this method to make sure project table names are not actually namespaced in migrations.
85+ def unnamespaced_table_name
86+ @unnamespaced_table_name ||= begin
87+ base = pluralize_table_names? ? plural_name : singular_name
88+ ( regular_class_path + [ base ] ) . join ( '_' )
89+ end
90+ end
91+
7392 def model_has_attachment?
7493 !attachment_attributes ( ) . empty?
7594 end
0 commit comments