You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Those are then each being converted to an array by CVS.parse_line in Resource#verify_keys like so:
'business_id'=>['123']
ActiveRecord will convert where(business_id: ['123']) to an in clause which is effectively an OR operation. Mongoid (and Mongo), however, will use the array as the value (since Mongo supports arrays as fields). This does not have the same semantics as an in clause in AR. As a result, our filters return no results because obviously we are not storing the business_id as an array.
We looked at tweaking this behavior in the verify_filter method but quickly realized that method is used for other purposes. Many tests broke after we applied the following:
defverify_filter(filter,raw,context=nil)filter_values=caserawwhenStringparts=CSV.parse_line(raw)parts.length > 1 ? parts : rawelserawendifis_filter_association?(filter)verify_association_filter(filter,filter_values,context)elseverify_custom_filter(filter,filter_values,context)endend
We'd love to help out with a patch but could use some guidance on how you think this should be handled.
The text was updated successfully, but these errors were encountered:
def self.apply_filter(records, filter, value)
if value.is_a?(Array)
raise "Not Supported: value contains >1 element: #{value}" if value.length > 1
value = value.first
end
records.where(filter => value)
end
Obviously, this doesn't work if the filter does contain an array of elements.
We are trying to retrieve documents from Mongo using the filters business_id and person_id. With the filter values like this:
http://localhost:3000/api/v1/emails?filter[business_id]=123
Those are then each being converted to an array by CVS.parse_line in
Resource#verify_keys
like so:ActiveRecord will convert
where(business_id: ['123'])
to anin
clause which is effectively an OR operation. Mongoid (and Mongo), however, will use the array as the value (since Mongo supports arrays as fields). This does not have the same semantics as anin
clause in AR. As a result, our filters return no results because obviously we are not storing the business_id as an array.We looked at tweaking this behavior in the
verify_filter
method but quickly realized that method is used for other purposes. Many tests broke after we applied the following:We'd love to help out with a patch but could use some guidance on how you think this should be handled.
The text was updated successfully, but these errors were encountered: