# The find methods for a model class

**URL:** <https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787>\
**Category:** Rails\
**Created:** [April 6, 2009, 1:51am UTC](https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787 "2009-04-06T01:51:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dc4da7/32.png) [@leon](https://www.ruby-forum.com/u/leon)\
**Post date:** [April 6, 2009, 1:51am UTC](https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787/1 "2009-04-06T01:51:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dc4da7/32.png) [@leon](https://www.ruby-forum.com/u/leon)\
**Post date:** [April 6, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787/2 "2009-04-06T16:55:14Z")

</div>

On Sun, Apr 5, 2009 at 6:50 PM, Leon [removed\_email\_address@domain.invalid](mailto: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:

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![leon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dc4da7/32.png) [@leon](https://www.ruby-forum.com/u/leon)\
**Post date:** [April 6, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787/3 "2009-04-06T20:55:13Z")

</div>

You could also check out the guides at:

> **[Active Record Query Interface — Ruby on Rails Guides](https://guides.rubyonrails.org/active_record_querying.html#dynamic-finders)**
>
> Active Record Query InterfaceThis guide covers different ways to retrieve data from the database using Active Record.After reading this guide, you will know: How to find records using a variety of methods and conditions. How to specify the order,...

---

<div class="post-metadata">

**Author:** ![leon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/dc4da7/32.png) [@leon](https://www.ruby-forum.com/u/leon)\
**Post date:** [April 6, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/the-find-methods-for-a-model-class/164787/4 "2009-04-06T21:11:58Z")

</div>

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.
