lib/administrate/search.rb in administrate-0.14.0 vs lib/administrate/search.rb in administrate-0.15.0
- old
+ new
@@ -80,12 +80,12 @@
def query_template
search_attributes.map do |attr|
table_name = query_table_name(attr)
searchable_fields(attr).map do |field|
- attr_name = column_to_query(field)
- "LOWER(CAST(#{table_name}.#{attr_name} AS CHAR(256))) LIKE ?"
+ column_name = column_to_query(field)
+ "LOWER(CAST(#{table_name}.#{column_name} AS CHAR(256))) LIKE ?"
end.join(" OR ")
end.join(" OR ")
end
def searchable_fields(attr)
@@ -107,11 +107,11 @@
end
end
def search_results(resources)
resources.
- joins(tables_to_join).
+ left_joins(tables_to_join).
where(query_template, *query_values)
end
def valid_filters
if @dashboard_class.const_defined?(:COLLECTION_FILTERS)
@@ -126,14 +126,17 @@
end
def query_table_name(attr)
if association_search?(attr)
provided_class_name = attribute_types[attr].options[:class_name]
- if provided_class_name
- provided_class_name.constantize.table_name
- else
- ActiveRecord::Base.connection.quote_table_name(attr.to_s.pluralize)
- end
+ unquoted_table_name =
+ if provided_class_name
+ Administrate.warn_of_deprecated_option(:class_name)
+ provided_class_name.constantize.table_name
+ else
+ @scoped_resource.reflect_on_association(attr).klass.table_name
+ end
+ ActiveRecord::Base.connection.quote_table_name(unquoted_table_name)
else
ActiveRecord::Base.connection.
quote_table_name(@scoped_resource.table_name)
end
end