Hi, According to http://guides.rubyonrails.org/active_record_querying.html, "first" does not use "ORDER BY ID" to bring the first record. Whereas "last" does. I find this inconsistent. I can also say that this is buggy on MySQL. "....limit 1" does not always bring the record with the minimum id. I can link you to the following that verifies my statement: http://forums.mysql.com/read.php?22,530328,530328#msg-530328 Do you think that you can change "first" to be consistent with "last" (that does the order by id desc)? BR Panayotis -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
It is already done at master branch. https://github.com/rails/rails/commit/66b9e4c857b5987a52f0442ae382ee18dc3dd30a Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Fri, Feb 22, 2013 at 1:26 PM, Panayotis Matsinopoulos < panayotis@matsinopoulos.gr> wrote:> Hi, > > According to http://guides.rubyonrails.org/active_record_querying.html, > "first" does not use "ORDER BY ID" to bring the first record. Whereas > "last" does. > I find this inconsistent. I can also say that this is buggy on MySQL. > "....limit 1" does not always bring the record with the minimum id. I can > link you to the following that > verifies my statement: > http://forums.mysql.com/read.php?22,530328,530328#msg-530328 > > Do you think that you can change "first" to be consistent with "last" > (that does the order by id desc)? > > BR > Panayotis > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
This is already fixed on Rails 4.0 On Feb 22, 2013, at 4:26 PM, Panayotis Matsinopoulos wrote:> Hi, > > According to http://guides.rubyonrails.org/active_record_querying.html, "first" does not use "ORDER BY ID" to bring the first record. Whereas "last" does. > I find this inconsistent. I can also say that this is buggy on MySQL. "....limit 1" does not always bring the record with the minimum id. I can link you to the following that > verifies my statement: http://forums.mysql.com/read.php?22,530328,530328#msg-530328 > > Do you think that you can change "first" to be consistent with "last" (that does the order by id desc)? > > BR > Panayotis > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > >Cumprimentos, Luís Ferreira -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Just a thought, how does this work with legacy tables that have no PK? What makes them possible now is that you can filter down with ''where'' onto a single record and get .first out without triggering a fetch through ID. Perhaps implement an "any" finder method with same function as the old "first" ? Borna On Friday, February 22, 2013 5:33:29 PM UTC+1, Zamith wrote:> > This is already fixed on Rails 4.0 > > On Feb 22, 2013, at 4:26 PM, Panayotis Matsinopoulos wrote: > > Hi, > > According to http://guides.rubyonrails.org/active_record_querying.html, > "first" does not use "ORDER BY ID" to bring the first record. Whereas > "last" does. > I find this inconsistent. I can also say that this is buggy on MySQL. > "....limit 1" does not always bring the record with the minimum id. I can > link you to the following that > verifies my statement: > http://forums.mysql.com/read.php?22,530328,530328#msg-530328 > > Do you think that you can change "first" to be consistent with "last" > (that does the order by id desc)? > > BR > Panayotis > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-co...@googlegroups.com <javascript:>. > To post to this group, send email to rubyonra...@googlegroups.com<javascript:> > . > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > Cumprimentos, > Luís Ferreira > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Sat, Feb 23, 2013 at 8:44 PM, Borna Novak <dosadnizub@gmail.com> wrote:> how does this work with legacy tables that have no PK? What makes them > possible now is that you can filter down with ''where'' onto a single record > and get .first out without triggering a fetch through ID. Perhaps implement > an "any" finder method with same function as the old "first" ?Yep, in Rails 4 the new #take method is the old #first: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/finder_methods.rb#L57-L66 Xavier -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Thanks Xavier :) On Friday, February 22, 2013 5:26:27 PM UTC+1, Panayotis Matsinopoulos wrote:> > Hi, > > According to http://guides.rubyonrails.org/active_record_querying.html, > "first" does not use "ORDER BY ID" to bring the first record. Whereas > "last" does. > I find this inconsistent. I can also say that this is buggy on MySQL. > "....limit 1" does not always bring the record with the minimum id. I can > link you to the following that > verifies my statement: > http://forums.mysql.com/read.php?22,530328,530328#msg-530328 > > Do you think that you can change "first" to be consistent with "last" > (that does the order by id desc)? > > BR > Panayotis >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.