Reputation: 8498
Currently I'm working on a gem, which overrides ActiveRecords where
. By working on that, I stumbled on two different find_by
implementations. One is in the core and it uses some kind of cache, whereas the one from the FinderMethods
module calls where
directly. What is the difference between these two implementations? When is which used?
Upvotes: 3
Views: 126
Reputation: 4413
I think it's that way: When you use something like this:
User.find_by(...)
The ActiveRecord::Core#find_by
is called, as the Core is included into Base from which you inherit.
But if you do something like:
User.first.products.find_by(...)
The ActiveRecord::Relation (includes FinderMethods
here) will call FinderMethods#find_by
I don't know why this is implemented like that, but I'm sure there's a reason for this.
Upvotes: 2