Forum: Ruby on Rails Passing id arrays to sql

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.
Will M. (Guest)
on 2006-05-19 09:23
Is there a way to pass an id array to find()?
Jon Evans (Guest)
on 2006-05-19 15:49
(Received via mailing list)
Hi Will,

On 19 May 2006, at 06:23, Will M. wrote:

> Is there a way to pass an id array to find()?

Yes.

from http://api.rubyonrails.com/classes/ActiveRecord/Ba...

> 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.

> Examples for find by id:
>
>   Person.find(1)       # returns the object for ID = 1
>   Person.find(1, 2, 6) # returns an array for objects with IDs in
> (1, 2, 6)
>   Person.find([7, 17]) # returns an array for objects with IDs in
> (7, 17)
>   Person.find([1])     # returns an array for objects the object
> with ID = 1


Jon

P.S. Just trying it would have been way quicker than asking. :)
This topic is locked and can not be replied to.