Skip to content

Instantly share code, notes, and snippets.

@bencrouse
Created October 19, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencrouse/e8af3b4a762a339d059fcfb7716a430e to your computer and use it in GitHub Desktop.
Save bencrouse/e8af3b4a762a339d059fcfb7716a430e to your computer and use it in GitHub Desktop.
Mongoid Criteria merging fixes
_key == '$in' ? new_val & old_val : old_val | new_val
# fairly defensive fix
if _key == '$in'
new_val & old_val
elsif old_val.respond_to?(:|)
old_val | new_val
else
new_val
end
# maybe riskier fix
if old_val == new_val
new_val
elsif _key == '$in'
new_val & old_val
else
old_val | new_val
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment