On 6 July 2013 11:15, Geoffroy Gomet <geoffroy.go...@gmail.com> wrote: > Hi, > > As of Rails 4, the order is by default based on the id DESC. > So Model.last produces the following sql: > > SELECT * FROM models ORDER BY models.id DESC LIMIT 1 > > > That said, I've no idea why you only get a part of the records back.
It is likely that he is getting all records back (as shown by #count) and that 138 is the lowest id. Colin > > Were you able to validates all those numbers directly on the DB? > > Regards > > Geoffroy > > Op vrijdag 5 juli 2013 23:16:14 UTC+2 schreef Colin Law het volgende: >> >> On 5 July 2013 18:06, zip py <li...@ruby-forum.com> wrote: >> > Hi >> > >> > I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart >> > from I just ran into an issue. >> > >> > Lets say I have a model called MyModel that has 150 records. >> > >> > If in IRB I try: >> > >> >> test = MyModel.all >> > >> > Only 138 records are returned. >> >> How do you know? >> >> > >> > If I now try: >> > >> >> lastRecord = test.last >> > >> > The record I get has an ID of 138 >> >> If you have not specified an order clause then the order you get the >> records in is undefined, so the last record is not necessarily the >> highest id. >> >> > >> > And yet if I try: >> > >> >> test.count >> > >> > It returns the correct value - 50! >> >> I presume you mean 150 >> >> Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLufE9m_MsiCtYnoeaKHebHjM_CjyksyZrssh6AFaE%2BGVA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.