I'm am keen to keep leaning on DM's agnostic goodness though :-) Thanks for the suggestion
Rolly On Mar 6, 3:06 am, George <[email protected]> wrote: > If you're desperate for a solution and prepared to provide your own > query then I suppose you could use this sort of uglyness...! > > ...ORDER BY CHARINDEX( ','+CAST(id AS varchar(10))+',', ', > 946,157,688,947,948,949,' ) > > perhaps substituting the list of IDs using DM's handy '?' parameter > feature. > > Not so helpful if you need to rely on DM's goodness to remain database > agnostic though :( > > George > > On Mar 4, 7:17 am, Rolly <[email protected]> wrote: > > > > > Thanks Gary, that what I figured but it's good to know for certain. > > > On Mar 4, 11:12 am, Gary <[email protected]> wrote: > > > > 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.
