Sha256: 0b4b157ed7bf810d9c59e77477ecaf84c94f2bc2abc965d6ef0a1aeaa036e246

Contents?: true

Size: 697 Bytes

Versions: 1

Compression:

Stored size: 697 Bytes

Contents

require 'active_record'

module ActiveRecordMysqlIndexHint
  def use_index(*args)
    from_with_index_hint 'USE', *args
  end

  def force_index(*args)
    from_with_index_hint 'FORCE', *args
  end

  def ignore_index(*args)
    from_with_index_hint 'IGNORE', *args
  end

  private
  def from_with_index_hint(hint_type, *args)
    return self if args.blank?
    indexes = args.map {|index| connection.quote_column_name index }
    self.from([Arel.sql("#{quoted_table_name} #{hint_type} INDEX(#{indexes.join(', ')})")])
  end
end

ActiveSupport.on_load :active_record do
  ActiveRecord::Base.extend ActiveRecordMysqlIndexHint
  ActiveRecord::Relation.send :include, ActiveRecordMysqlIndexHint
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-mysql-index-hint-0.0.4 lib/activerecord-mysql-index-hint.rb