To further explain my reasoning:
first() is a method I almost exclusively use in the console. I think of it like “get me the first record that matches some conditions or scope I specify”. If there was a
single method, would the implementation be much different?
For production code, I use dynamic finders against columns that are constrained with a unique key—e.g.:
The implementation for these is (I believe) identical to
first. I only use
first in combination with ordering to say “get me the user with most comments” or “get me the most recent comment”, but this is only for presentational purposes and you can agree that such a use case doesn’t come often.
But, it’s obvious that it’s completely wrong to use
find_by on some column(s) that are not under a unique constraint. This should always be used:
I guess that all I’m trying to say can be summed up as:
- if the column is unique-constrained, you should use find_by_column (or
first with conditions or scope);
- if the column is not unique, you must use find_all_by_column (or alternatives);
- there’s no need for an extra method.