lib/pg_search/configuration/column.rb in pg_search-0.1.1 vs lib/pg_search/configuration/column.rb in pg_search-0.2
- old
+ new
@@ -1,5 +1,7 @@
+require 'digest'
+
module PgSearch
class Configuration
class Column
attr_reader :weight, :association
@@ -9,20 +11,20 @@
@model = model
@association = association
end
def table
- foreign? ? @model.reflect_on_association(association).table_name : @model.table_name
+ foreign? ? @association.table_name : @model.table_name
end
def full_name
"#{@model.connection.quote_table_name(table)}.#{@model.connection.quote_column_name(@column_name)}"
end
def to_sql
name = if foreign?
- "#{self.subselect_alias}.#{self.alias}"
+ "#{@association.subselect_alias}.#{self.alias}"
else
full_name
end
"coalesce(#{name}, '')"
end
@@ -30,14 +32,11 @@
def foreign?
@association.present?
end
def alias
- ["pg_search", table, association, @column_name].compact.join('_')
- end
-
- def subselect_alias
- "#{self.alias}_subselect"
+ name = [association.subselect_alias, @column_name].compact.join('_')
+ "pg_search_#{Digest::SHA2.hexdigest(name)}"
end
end
end
end