Skip to content

Commit 3ab4ab5

Browse files
committed
Fix conflicting annotations for multiple-database scenario
Given a Rails application with multiple databases, tables in two databases with the same table name, and corresponding models with different names, some files get annotated with the wrong table's schema. The issue is that some of the patterns include `%TABLE_NAME%`, which will be identical between the two tables, even though they have different model names. This fixes the issue by eliminating the use of the table name when the model is not connected to the primary database. Fixes #891.
1 parent 5d01c41 commit 3ab4ab5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/annotate/annotate_models.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def annotate(klass, file, header, options = {})
538538
klass.reset_column_information
539539
info = get_schema_info(klass, header, options)
540540
model_name = klass.name.underscore
541-
table_name = klass.table_name
541+
table_name = klass.table_name if klass.connection_specification_name == ActiveRecord::Base.name
542542
model_file_name = File.join(file)
543543
annotated = []
544544

@@ -760,7 +760,7 @@ def remove_annotations(options = {})
760760
klass = get_model_class(file)
761761
if klass < ActiveRecord::Base && !klass.abstract_class?
762762
model_name = klass.name.underscore
763-
table_name = klass.table_name
763+
table_name = klass.table_name if klass.connection_specification_name == ActiveRecord::Base.name
764764
model_file_name = file
765765
deannotated_klass = true if remove_annotation_of_file(model_file_name, options)
766766

0 commit comments

Comments
 (0)