diff --git a/lib/data_tables/adapter.rb b/lib/data_tables/adapter.rb index fdc51b0..e99cfb5 100644 --- a/lib/data_tables/adapter.rb +++ b/lib/data_tables/adapter.rb @@ -38,7 +38,6 @@ def serializable_hash(options) end @results = search(@results) - # search_by = search(@results) # Rails.logger.warn "SEARCH BY: #{search_by}" @results = order_by.inject(@results) { |r, o| r.order(o) } diff --git a/lib/data_tables/modules/search.rb b/lib/data_tables/modules/search.rb index 6a2383d..45610e7 100644 --- a/lib/data_tables/modules/search.rb +++ b/lib/data_tables/modules/search.rb @@ -21,6 +21,7 @@ def search return @collection unless (default_search = request_parameters.dig(:search, :value)).present? model = @collection.try(:model) || @collection + arel_table = model.arel_table columns = searchable_columns(default_search) searches = DataTables.flat_keys_to_nested columns @@ -28,10 +29,17 @@ def search or_clause = nil search_by = searches.collect do |k, query| if query.is_a? Hash - klass = model.reflect_on_association(k).klass + assoc = model.reflect_on_association(k) + assoc_klass = assoc.klass + assoc_arel_table = assoc_klass.arel_table - @collection = @collection.joins(k) - klass.arel_table[query.first.first].matches(query.first.last) + if model.respond_to? :left_outer_join + @collection = @collection.left_outer_join(k) + else + @collection = @collection.includes(k).references(k) + end + + assoc_arel_table[query.first.first].matches(query.first.last) else if (column = model.columns.find { |c| c.name == k.to_s }) case column.type diff --git a/lib/data_tables/responder/version.rb b/lib/data_tables/responder/version.rb index 967276d..b6a7fdb 100644 --- a/lib/data_tables/responder/version.rb +++ b/lib/data_tables/responder/version.rb @@ -1,5 +1,5 @@ module DataTables module Responder - VERSION = "0.1.0" + VERSION = '0.1.1' end end