Sha256: 18be90e45cc470f758d585768cde096552bbf58849b2d39d16e393c19a7c2b35

Contents?: true

Size: 1016 Bytes

Versions: 17

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::ActiveRecord::SimpleManyQuery <
  ThinkingSphinx::ActiveRecord::PropertyQuery

  def to_s
    "#{identifier} from #{source_type}; #{queries.join('; ')}"
  end

  private

  def reflection
    @reflection ||= source.model.reflect_on_association column.__stack.first
  end

  def quoted_foreign_key
    quote_with_table reflection.join_table, reflection.foreign_key
  end

  def quoted_primary_key
    quote_with_table reflection.join_table, reflection.association_foreign_key
  end

  def range_sql
    "SELECT MIN(#{quoted_foreign_key}), MAX(#{quoted_foreign_key}) FROM #{quote_column reflection.join_table}"
  end

  def to_sql
    selects = [
      "#{quoted_foreign_key} #{offset} AS #{quote_column('id')}",
      "#{quoted_primary_key} AS #{quote_column(property.name)}"
    ]
    sql  = "SELECT #{selects.join(', ')} FROM #{quote_column reflection.join_table}"
    sql += " WHERE (#{quoted_foreign_key} BETWEEN $start AND $end)" if ranged?
    sql
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/active_record/simple_many_query.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/active_record/simple_many_query.rb