Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to use MySQL clause "Use index('index_name')" using ActiveRecord

I want to use the SQL clause "Use index('index_name')" to an ActiveRecord query, does anyone knows a good way to do it with Activerecord I wanted to avoid adding string directly to the query.

like image 665
VelLes Avatar asked Nov 04 '22 15:11

VelLes


1 Answers

I use this in my models:

def self.use_index(index)
  from("#{self.table_name} USE INDEX(#{index})")
end
like image 75
James Daniels Avatar answered Nov 11 '22 20:11

James Daniels