Sha256: b6c1cdb138e6d3a4ff273a8500de540ef595b84eb27324be5203e0351461b3c2
Contents?: true
Size: 871 Bytes
Versions: 6
Compression:
Stored size: 871 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.collect { |column| association_for column.split(".").first }.uniq end def association_for(column) alias_value = scope.reflection.aliases[column] association = alias_value.respond_to?(:table_name) ? alias_value.table_name : alias_value association ||= column association.to_sym end end end
Version data entries
6 entries across 6 versions & 1 rubygems