# ActiveRecord find in order for an array parameter

**URL:** <https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254>\
**Category:** Rails\
**Created:** [September 22, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254 "2008-09-22T23:25:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wheels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@wheels](https://www.ruby-forum.com/u/wheels)\
**Post date:** [September 22, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254/1 "2008-09-22T23:25:27Z")

</div>

How can i make ActiveRecord find in order for an array parameter?

Ex. for Test.find([1, 2, 3, 4, 5])  
it should return test.id=1 as the first entry.

Right, it just returns in a random order.

thanks

---

<div class="post-metadata">

**Author:** ![wheels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@wheels](https://www.ruby-forum.com/u/wheels)\
**Post date:** [September 23, 2008, 7:29am UTC](https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254/2 "2008-09-23T07:29:22Z")

</div>

You’ll need to use the :order option.  
Test.find([1,2,3,4,5], :order =\> “id”)

-Dan M.  
[http://www.dcmanges.com/blog](http://www.dcmanges.com/blog)

---

<div class="post-metadata">

**Author:** ![wheels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@wheels](https://www.ruby-forum.com/u/wheels)\
**Post date:** [September 23, 2008, 7:36am UTC](https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254/3 "2008-09-23T07:36:59Z")

</div>

Assuming that you’re trying to order them by the id, you can sort the  
array when you pass it into .find.

Test.find( array\_name.sort )

Good luck!

Cheers,  
Robby

On Mon, Sep 22, 2008 at 10:19 PM, Dan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Ex. for Test.find([1, 2, 3, 4, 5])  
> > it should return test.id=1 as the first entry.
> > 
> > Right, it just returns in a random order.
> > 
> > thanks

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![wheels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@wheels](https://www.ruby-forum.com/u/wheels)\
**Post date:** [September 23, 2008, 8:03am UTC](https://www.ruby-forum.com/t/activerecord-find-in-order-for-an-array-parameter/149254/4 "2008-09-23T08:03:56Z")

</div>

wheels wrote:

> How can i make ActiveRecord find in order for an array parameter?

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/158dc2d879b2fb1](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/158dc2d879b2fb1)

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)
