I’ve seen class methods that act as scopes use self
or scoped
for conditionals where their SQL should not be chained:
def self.search(query)
if query.blank?
self
else
where('name @@ ?', query)
end
end
or:
def self.search(query)
if query.blank?
scoped
else
where('name @@ ?', query)
end
end
Is there anything wrong with the self
version? What could go wrong?