ActiveRecord::QueryMethods#where_values_hash to include NotEqual wheres?

Usage

For testing purposes I’d say it would be useful to have #where_values_hash return the not conditions too in either:

  • a separate method (#where_not_values_hash),

  • by modifying the currently returned hash’s structure from #where_values_hash.

Relevant code parts

Current Rails 4.2.5 implementation - https://github.com/rails/rails/blob/4-2-5/activerecord/lib/active_record/relation.rb#L560

Current Rails 5.x.x implementation - https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/where_clause.rb#L48

Examples

Example that returns not conditions in #where_values_hash :


> User.where(active: true).where.not(name: 'joe').where_values_hash

=> {"positive" => {"active": true}, "negative" => {"name": "joe"} }

Example that returns not conditions in new method #where_not_values_hash:


> User.where(active: true).where.not(name: 'joe').where_not_values_hash

=> {"name": "joe"}

Closure

If you agree with this idea, I’ll gladly work on a PR.