Sha256: 9c19dea50f44c2bd136c97065c6ae8811387a6a6da5871ee39a272d61f53a326

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

module SearchCop
  class QueryBuilder
    attr_accessor :query_info, :scope, :sql

    def initialize(model, query, scope)
      self.scope = scope
      self.query_info = QueryInfo.new(model, scope)

      arel = SearchCop::Parser.parse(query, query_info).optimize!

      self.sql = SearchCop::Visitors::Visitor.new(model.connection).visit(arel)
    end

    def associations
      all_associations - [query_info.model.name.tableize.to_sym]
    end

    private

    def all_associations
      scope.reflection.attributes.values.flatten.uniq.collect { |column| column.split(".").first }.collect { |column| scope.reflection.aliases[column] || column.to_sym }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search_cop-1.0.3 lib/search_cop/query_builder.rb