annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Cannot add indexes or foreign keys

Open istrasci opened this issue 7 months ago • 0 comments

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

  • annotate version: 3.2.0
  • rails version: 7.0.8.3
  • ruby version: 3.3.1

istrasci avatar Jul 26 '24 00:07 istrasci