EugZol / where_exists

Adds the power of SQL Exists to ActiveRecord
MIT License
110 stars 18 forks source link

Return all or none scope when build_exists_string produces no query #18

Closed holstvoogd closed 3 years ago

holstvoogd commented 4 years ago

This allows for the use of where(not)exists with a polymoprhic belongs_to on an empty relation.

We ran into the issue where parent.transactions.where_not_exists(:document)' basically resulted inSELECT * FROM transactions WHERE parent_id = 1234 AND (NOT ())`.

This fixes that case and a possible situation where, using the above example, no transactions have documents.

gstokkink commented 3 years ago

👍

@EugZol can this be merged?

EugZol commented 3 years ago

Looks good. Thanks @holstvoogd!

And thanks @gstokkink for pinging.