If you need a method that finds all but raises exception if the relation is empty, you can create such new method for your models yourself (or mixin to ActiveRecord::QueryMethods). Something like:
def where!(*args)
rel = where(*args)
raise RecordNotFound if rel.empty?
rel
end
No, those ‘dynamic finders’ based on your attribute names aren’t get removed. If you have an attribute name hash, you should be able to still do User.find_by_hash!
Wouldn’t it be more intuitive to use the #first! method for this purpose?
i.e., User.find_by_hash!(hash) is the same as User.where(hash: hash).first!
I know that I often chain where conditions together (especially when using scopes), so it makes sense to raise the exception only when I actually try to fetch the record from the database.