1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Query for negative associations as subquery

When a collection association (has_many, etc) is searched for negative
conditions (NOT...), a JOIN will still include other rows that match.

The implied meaning is that it should only select where *none* of the
associations match, but the actual result still selects records where
*any* of the joined associations match.

This implementation removes joins that were added while building the
conditions and moves them into a subquery if needed.
This commit is contained in:
Andrew Vit 2016-01-08 16:18:24 -08:00
parent eb8257092a
commit 96d0fd75ad
6 changed files with 178 additions and 22 deletions

View file

@ -27,6 +27,8 @@ module Ransack
@join_dependency = join_dependency(@object)
@join_type = options[:join_type] || Polyamorous::OuterJoin
@search_key = options[:search_key] || Ransack.options[:search_key]
@associations_pot = {}
@lock_associations = []
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
@base = @join_dependency.join_root