Sha256: 8613e03e1da34a52c93912b2f291767c31b0ceef6afd9c6b43b19526315a5ece
Contents?: true
Size: 928 Bytes
Versions: 2
Compression:
Stored size: 928 Bytes
Contents
require "digest" module PgSearch class Configuration class Association attr_reader :columns def initialize(model, name, column_names) @model = model @name = name @columns = Array(column_names).map do |column_name, weight| Column.new(column_name, weight, @model, self) end end def table_name @model.reflect_on_association(@name).table_name end def join(primary_key) selects = columns.map do |column| "string_agg(#{column.full_name}, ' ') AS #{column.alias}" end.join(", ") relation = @model.joins(@name).select("#{primary_key} AS id, #{selects}").group(primary_key) "LEFT OUTER JOIN (#{relation.to_sql}) #{subselect_alias} ON #{subselect_alias}.id = #{primary_key}" end def subselect_alias Configuration.alias(table_name, @name, "subselect") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pg_search-0.3.1 | lib/pg_search/configuration/association.rb |
pg_search-0.3 | lib/pg_search/configuration/association.rb |