It's calling an extra query and leaving it there: "first query ~ (0.000097) SELECT "id", "age", "name" FROM "users" ORDER BY "age" ["Jill", "Mary", "Bob", "Jack"] "Jack" ["Jill", "Mary", "Bob", "Jack"] second query ~ (0.000081) SELECT "id", "age", "name" FROM "users" ORDER BY "age" DESC LIMIT 1 "Jack" ~ (0.000078) SELECT "id", "age", "name" FROM "users" ORDER BY "age" DESC ["Bob", "Mary", "Jill", "Jack"]"
I don't think it is a bug, here's how it works: "s = User.all(:order => [:age.asc])" "s" is just a DataMapper::Query until you call something on it. "s.map{|r| r.name}" <- now you've called something so the query executes here. "s" is now a reference to a DataMapper::Collection, because you called the query "s.last.name" -> #last is calling DataMapper::Collection#last In the second part: "s = User.all(:order => [:age.asc])" "s" again is just a query at this point "s.last.name" the query is updated with #last, so now the query is like this: User.all(:order => [:age.asc]).last => which is like User.all(:order => [:age.asc]).update(:limit => 1, :order => [:age.desc]) because DM will give you the "last result in users sorted by age asc" which is the same as saying the "first result in users sorted by age desc" Here's how it -might- be a bug... (in the second example) "s" is a reference to an updated query as opposed to a single User instance, or it might be a collection, I don't know here... "s.map{|r| r.name}" #map is being called on the updated query On Feb 28, 11:01 pm, MarkMT <mark.thom...@ieee.org> wrote: > Sorry, I pasted the url for another gist I had been looking at from a > different thread. This is the one I meant to refer to - > > http://gist.github.com/318072 > > On Feb 28, 10:57 pm, MarkMT <mark.thom...@ieee.org> wrote: > > > > > I've run into a problem that seems like it might be a bug... > > > If I retrieve a set of records using the ':order' option and then call > > 'last' on the resulting collection, the collection seems to end up > > being mis-ordered. The problem only seems to manifest itself if I > > haven't made an attempt to do anything with the ordered collection > > prior to calling 'last'. > > > Here's a gist that illustrates -http://gist.github.com/305019. > > > This is with dm 0.10.2. Am I misunderstanding how this should work? > > > Mark. -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.