ctran / annotate_models

Annotate Rails classes with schema and routes info
Other
4.41k stars 598 forks source link

Cannot add indexes or foreign keys #1025

Open istrasci opened 2 months ago

istrasci commented 2 months ago

I see the options --show-indexes and --show-foreign-keys, but if I run annotate with them, I cannot get it to work. What is annotate looking for to be able to include these in the annotations? Is it looking at the DB migrations? Is it looking at belongs_to associations in the models? Both? Something else?

My migrations contains t.index statements within the create_table calls, as well as add_foreign_key statements as necessary. My models are for legacy tables and don't use the default :id column, so in the belongs_to associations I must use :foreign_key to specify the column. Like:

class MyModel
  belongs_to :other_model, class_name: 'OtherModel',
    primary_key: 'other_model_code',
    foreign_key:  'my_model_code',
    inverse_of: 'my_model'
end

So I'm not sure if I have something set up incorrectly, or if I'm possibly doing something else wrong. I'd appreciate any help.

Commands

$ bundle exec annotate --models --show-indexes --show-foreign-keys

Version