# Map belongs_to associations to the corresponding referenced tables
assoc_map = models_with_table.map do |model|
  target_tables = model.reflect_on_all_associations(:belongs_to).map do |assoc|
    {
      table_name: assoc.class_name.safe_constantize&.table_name,
      column_name: "#{assoc.name}_id",
    }
  end.compact
  [model.table_name, target_tables]
end.to_h