module ActiveRecordWhereAssoc::SqlReturningMethods

The methods in this module return partial SQL queries. These are used by the main methods of this gem: the #where_assoc_* methods located in RelationReturningMethods. But in some situation, the SQL strings can be useful to do complex manual queries by embedding them in your own SQL code.

Those methods should be used directly on your model’s class. You can use them from a relation, but the result will be the same, so your intent will be clearer by doing it on the class directly.

# This is the recommended way:
sql = User.assoc_exists_sql(:posts)

# While this also works, it may be confusing when reading the code:
sql = my_filtered_users.assoc_exists_sql(:posts)
# the sql variable is not affected by my_filtered_users.