change ActiveRecord joins query with custom generated SQL

This commit is contained in:
Bilal
2020-04-20 19:33:29 +02:00
parent 4e382d7c1a
commit f4bec85161
2 changed files with 73 additions and 3 deletions

View File

@@ -55,8 +55,16 @@ module PgSearchable
def ts_search(value)
return if @ts_search_fields.blank? || value.blank?
includes(@ts_joins).references(:all).where(
TextToSqlQuery.new(value, @ts_search_fields, @default_fields, @ts_search_fields_mappings).where_clause).distinct
model = ancestors.first
sql_query_object = TextToSqlQuery.new(
value,
@ts_search_fields,
@default_field,
@ts_search_fields_mappings,
@ts_joins,
model
)
joins(sql_query_object.join_clause).where(sql_query_object.where_clause).distinct
end
def should_update_cache_field?