Add predicate method to tell if record exists #2100
hi-tech-jazz
started this conversation in
General
Replies: 1 comment 5 replies
-
I don't want to add a method for this. The best method name I can think of is class Sequel::Dataset
def exists?; !empty? end
end
class Sequel::Model
def self.exists?; dataset.exists? end
end |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @jeremyevans!
Thanks for a great library.
I often find myself using
Sequel::Dataset#empty?
combined with the!
operator when I want to know if at least one record fulfilling some given conditions exists, however what I would like to write is really the inverse of said predicate to avoid the negation. The obvious name for such a method would beexists?
(with the benefit of matching ActiveRecord) but in the case of Sequel, the resemblance toSequel::Dataset#exists
andSequel::Model#exists?
might cause confusion. Before I ponder more on the tricky question of naming I want to ask: Would you be open for considering the addition of such a method or is it an optimization for readability that feels unneeded?Beta Was this translation helpful? Give feedback.
All reactions