app/models/effective/effective_datatable/resource.rb in effective_datatables-4.3.6 vs app/models/effective/effective_datatable/resource.rb in effective_datatables-4.3.7
- old
+ new
@@ -138,19 +138,24 @@
search[:collection].each { |k, v| search[:collection][k] = 'nil' if v == nil }
end
search[:value] ||= search.delete(:selected) if search.key?(:selected)
- search[:as] ||= :select if (search.key?(:collection) && opts[:as] != :belongs_to_polymorphic)
+ search[:as] ||= :select if search.key?(:collection)
search[:fuzzy] = true unless search.key?(:fuzzy)
if array_collection? && opts[:resource].present?
search.reverse_merge!(resource.search_form_field(name, collection.first[opts[:index]]))
elsif search[:as] != :string
search.reverse_merge!(resource.search_form_field(name, opts[:as]))
end
+
+ # Assign default include_null
+ if search[:as] == :select && !search.key?(:include_null)
+ search[:include_null] = true
+ end
end
end
def apply_belongs_to_attributes!
return unless active_record_collection?
@@ -158,13 +163,22 @@
changed = attributes.select do |attribute, value|
attribute = attribute.to_s
next unless attribute.ends_with?('_id')
associated = attribute.gsub(/_id\z/, '').to_sym # Replace last _id
- next unless columns[associated] && columns[associated][:as] == :belongs_to
- @_collection = @_collection.where(attribute => value)
- columns.delete(associated)
+ next unless columns[associated]
+
+ if columns[associated][:as] == :belongs_to
+ @_collection = @_collection.where(attribute => value)
+ columns.delete(associated)
+ elsif columns[associated][:as] == :belongs_to_polymorphic
+ associated_type = attributes["#{associated}_type".to_sym] || raise("Expected #{associated}_type attribute to be present when #{associated}_id is present on a polymorphic belongs to")
+
+ @_collection = @_collection.where(attribute => value).where("#{associated}_type" => associated_type)
+ columns.delete(associated)
+ end
+
end.present?
load_columns! if changed
end