Forum: Ruby on Rails The find methods for a model class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Leon (Guest)
on 2009-04-06 03:51
(Received via mailing list)
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
Greg D. (Guest)
on 2009-04-06 18:55
(Received via mailing list)
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:

http://api.rubyonrails.org/classes/ActiveRecord/As...



--
Greg D.
http://destiney.com/
Rick (Guest)
on 2009-04-06 22:55
(Received via mailing list)
You could also check out the guides at:

http://guides.rubyonrails.org/active_record_queryi...
Robert W. (Guest)
on 2009-04-06 23:11
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.
This topic is locked and can not be replied to.