ActiveRecord dynamic finder methods


#1

I’ve received conflicting answers to this question and I’d like to
confirm the correct answer.

When an ActiveRecord dynamic finder method is invoked, does it create
a new method and save it so the method actually exists the next time
it is called OR does it just evaluate the query based on the method
name every time.

I don’t have an opinion on which way is better, I just want to know
how it currently works.


#2

On Mar 17, 2006, at 4:41 PM, Mark V. wrote:

I’ve received conflicting answers to this question and I’d like to
confirm the correct answer.

When an ActiveRecord dynamic finder method is invoked, does it create
a new method and save it so the method actually exists the next time
it is called OR does it just evaluate the query based on the method
name every time.

I don’t have an opinion on which way is better, I just want to know
how it currently works.

You can always ask Ruby:

Member.respond_to? :find_by_first_name
=> false

Member.find_by_first_name(“James”)
=> #<Member:0x2223208 …>

Member.respond_to? :find_by_first_name
=> false

James Edward G. II