The find methods for a model class


#1

Hi,

I am doing some examples in a book on Roby on Rails. When a model
class is create with generate model command, it will create some
find_xxx methods on the fields. When the model have the relationships
with other models, the more find_xxx methods will be generated. How do
I know exactly how many and what kinds of find_xxx methods are
created?

Thanks.

Leon


#2

On Sun, Apr 5, 2009 at 6:50 PM, Leon removed_email_address@domain.invalid wrote:

I am doing some examples in a book on Roby on Rails. When a model
class is create with generate model command, it will create some
find_xxx methods on the fields. When the model have the relationships
with other models, the more find_xxx methods will be generated. How do
I know exactly how many and what kinds of find_xxx methods are
created?

The API docs explain all of these added methods here:


Greg D.
http://destiney.com/


#3

You could also check out the guides at:

http://guides.rubyonrails.org/active_record_querying.html#dynamic-finders


#4

Leon wrote:

Hi,

I am doing some examples in a book on Roby on Rails. When a model
class is create with generate model command, it will create some
find_xxx methods on the fields. When the model have the relationships
with other models, the more find_xxx methods will be generated. How do
I know exactly how many and what kinds of find_xxx methods are
created?

Realizing the links provided by Greg and Rick will contain the answers
you need, I wanted to make it clear that the precise answer to this
question is zero. I mean that none of these methods get created when the
model is created nor when relationships are defined.

These methods you’re referring to are called dynamic finders because
they do not exist until they are actually used at run time. The first
time they are used at runtime the method won’t be found so Ruby will
call it’s method_missing method. ActiveRecord’s version of
method_missing dynamically adds the requested method as long as it
follow the naming convention and contains appropriate arguments to
satisfy the new method. Subsequent calls to the same method will use the
dynamically generated one bypassing the need to call method_missing.