Well, I discovered this workaround: a = Task.all(:order => [ :ordering.asc ])[9]
Looks like this optimizes to what the previous one probably ought to. It uses OFFSET. On Thu, Jan 13, 2011 at 7:33 PM, lobati <[email protected]> wrote: > So I'm trying to get the nth result from the database: > > a = Task.all(:limit => 10, :order => [ :ordering.asc ]).last > > but this query, instead of returning the 10th item actually returns > the last item in the database. I get the same results if I do this: > > a = Task.all(:limit => 10, :order => [ :ordering.asc ]) > a = a.last > > However, I get the results I want if I do something like this: > > > a = Task.all(:limit => 10, :order => [ :ordering.asc ]) > a.each do |task| > # do nothing > end > a = a.last > > I gather this is the result of some query optimization going on, but > this is a bug, right? So for the time being, is there are better way > of forcing the query to take place before '.last' and/or is there a > more efficient way for me to get the 10th record with the above > condition? > > -- > 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]<datamapper%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en. > > -- 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.
