Last active
February 11, 2022 14:40
-
-
Save cutalion/131bb1cdf01ade85bd921b7eb8c494fa to your computer and use it in GitHub Desktop.
rom-sql's "Relation#exist?" using EXISTS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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