Skip to content

Instantly share code, notes, and snippets.

@cutalion
Last active February 11, 2022 14:40
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 cutalion/131bb1cdf01ade85bd921b7eb8c494fa to your computer and use it in GitHub Desktop.
Save cutalion/131bb1cdf01ade85bd921b7eb8c494fa to your computer and use it in GitHub Desktop.
rom-sql's "Relation#exist?" using EXISTS
# override original exist? so that it does not use COUNT()
def exist?(*args, &block)
sql = where(*args, &block).dataset.unordered.select(1).exists
db.select(sql.as(:exists)).first[:exists]
end
alias any? exist?
private
def db
dataset.db
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment