Open arturopie opened 5 years ago
Did you want to raise an ActiveRecord::RecordNotFound
exception when nothing is found given an id
?
Also, the dynamic finder methods appear to be mildly deprecated. Why use them instead of the AREL style?
@sskirby yes, we want the NotFound exception so our controllers return 404s. Right now we are reimplementing that behaviour in our repos, but having this in Vorpal/AR would be an enhancement and will lower the bar to use Vorpal.
We don't want to use dynamic finders (e.g. #find_by_name
), but just #find_by(name: n)
which is not deprecated.
I'm sure we can come up with something to make the your ActiveRecord::RecordNotFound
use-case easier!
I'm curious why you would like to use find_by(name: n)
instead of something like where(name: n)
?
.find_by(name: n)
is equivalent to .where(name: n).first
. So I guess it's just more convenient (one less call). It also feels more like Rails, so it's easier for people that are used to use Rails.
We like how, by using the Vorpal Mapper, we can use AR methods like
#where
inside a repo. We'd like the ability to use other methods like#find
or#find_by
as well, but these methods return an AR object instead of an ActiveRecord::Relation object, and that AR object does not have the usefulload_one
method.Here is an example
This method:
Crashes with the following error:
We want to use
find
because we want to raise a NoError exception if the record does not exist.