transform INNER JOIN to LEFT OUTER

This commit is contained in:
Bilal
2020-04-29 16:52:54 +02:00
parent e0fae50584
commit f8352dcaa1
2 changed files with 5 additions and 3 deletions

View File

@@ -47,7 +47,7 @@ module PgSearchable
def ts_add_scope
class_eval do
scope ts_scope_method, ->(value) do
resulting_ids = ts_search(value).map(&:id)
resulting_ids = ts_search(value).rows.map { |row| row[0] }
where(id: resulting_ids)
end
end
@@ -62,7 +62,9 @@ module PgSearchable
@ts_search_fields_mappings,
@ts_joins
)
distinct.joins(sql_query_object.join_clause).group(:id).having(sql_query_object.where_clause)
sql_query = select(:id).distinct.joins(sql_query_object.join_clause).group(:id).having(sql_query_object.where_clause)
modified_sql_query = sql_query.to_sql.gsub('INNER', 'LEFT OUTER') # TODO: Search terms should not be replaced!
ActiveRecord::Base.connection.exec_query(modified_sql_query)
end
def should_update_cache_field?

View File

@@ -31,7 +31,6 @@ class TextToSqlQuery
def join_clause
return nil if @joins.empty?
return *@joins
end
@@ -109,6 +108,7 @@ private
result.gsub!(/\_/, '\_')
result.tr!('\\', '\\')
result.gsub!(/%/, '\%')
result.downcase!
result
end
end