# Find\_all / find\_first deprecated : a question

**URL:** <https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993>\
**Category:** Rails\
**Created:** [August 30, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993 "2006-08-30T20:23:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [August 30, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993/1 "2006-08-30T20:23:56Z")

</div>

was reading  
[http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails](http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails)  
getting this rails app ready for 2.0 …

anyways, here’s a small snippet that i’m wondering about:

* * *

Using Deprecated Finders

## find\_all and find\_first have been deprecated over a year now. Stop using them. While you’re at it, stop using render\_partial. Their better educated cousin find can handle all their needs. Use find(:first), find(:all) and render :partial

i can understand using find(:all) instead of find\_all … but what about  
find\_all\_by\_field\_name … i love that little nugget. it couldn’t  
possibly be deprecated could it?

thanks

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [August 30, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993/2 "2006-08-30T21:09:59Z")

</div>

No, I believe those are here to stay.

~Jamie

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [August 30, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993/3 "2006-08-30T22:02:06Z")

</div>

Hi, I would recommend referencing the API docs for Rails at the  
following:

[http://api.rubyonrails.org/](http://api.rubyonrails.org/)

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [August 30, 2006, 10:08pm UTC](https://www.ruby-forum.com/t/find-all-find-first-deprecated-a-question/66993/4 "2006-08-30T22:08:07Z")

</div>

Hi, in regards to API documents, you should be using the following  
instead  
of find\_all and find\_first:

_find_(\*args)

Find operates with three different retrieval approaches:

- Find by id: This can either be a specific id (1), a list of ids (1,  
5, 6), or an array of ids ([5, 6, 10]). If no record can be found for  
all of  
the listed ids, then RecordNotFound will be raised.
- Find first: This will return the first record matched by the  
options  
used. These options can either be specific conditions or merely an  
order. If  
no record can matched, nil is returned.
- Find all: This will return all the records matched by the options  
used. If no records are found, an empty array is returned.

All approaches accept an option hash as their last parameter. The  
options  
are:

- :conditions: An SQL fragment like “administrator = 1” or [  
“user\_name = ?”, username ]. See conditions in the intro.
- :order: An SQL fragment like “created\_at DESC, name”.
- :group: An attribute name by which the result should be grouped.  
Uses the GROUP BY SQL-clause.
- :limit: An integer determining the limit on the number of rows that  
should be returned.
- :offset: An integer determining the offset from where the rows  
should be fetched. So at 5, it would skip the first 4 rows.
- :joins: An SQL fragment for additional joins like “LEFT JOIN  
comments ON comments.post\_id = id”. (Rarely needed). The records will  
be returned read-only since they will have attributes that do not  
correspond  
to the table’s columns. Pass :readonly =\> false to override.
- :include: Names associations that should be loaded alongside using  
LEFT OUTER JOINs. The symbols named refer to already defined  
associations.  
See eager loading under Associations.
- :select: By default, this is \* as in SELECT \* FROM, but can be  
changed if you for example want to do a join, but not include the  
joined  
columns.
- :readonly: Mark the returned records read-only so they cannot be  
saved or updated.

Examples for find first:

Person.find(:first) # returns the first object fetched by SELECT \*  
FROM people  
Person.find(:first, :conditions =\> [“user\_name = ?”, user\_name])  
Person.find(:first, :order =\> “created\_on DESC”, :offset =\> 5)

Examples for find all:

Person.find(:all) # returns an array of objects for all the rows  
fetched by SELECT \* FROM people  
Person.find(:all, :conditions =\> [“category IN (?)”, categories],  
:limit =\> 50)  
Person.find(:all, :offset =\> 10, :limit =\> 10)  
Person.find(:all, :include =\> [:account, :friends])  
Person.find(:all, :group =\> “category”)

Good luck,

-Conrad
