If there is a specific order from values of fields in the db, such as
by id, you can do:

Foo.all :id => [946, 157, 688, 947, 948, 949], :order => [:id]


But if it's an arbitrary order, you are out of luck, if you want to do
just one query.

a = [946, 157, 688, 947, 948, 949]
h = {}
Foo.all(:id => a).each{|x| h[x.id] = x}
a.map{|x| h[x]}

-Gary


On Mar 2, 4:05 pm, Rolly <[email protected]> wrote:
> I've been trying to retrieve a bunch of records based on an array of
> ids, say [946, 157, 688, 947, 948, 949], but I  need the results in
> the original order of the ids, so record 946, then 157, etc.
>
> I've trawled though the docs and source code and I know I can do
> something like Foo.all :id => [946, 157, 688, 947, 948, 949] to get a
> bunch of docs by id, but that doesn't seem to preserve the order. I
> assume it defaults to sorting by primary key instead.
>
> Is there some way to do this directly with DataMapper, or should I
> just try and sort them after the query?

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to