"last(5)" is, with regard to efficiency, equivalent to "limit(5).to_a".
On Fri, Jul 19, 2013 at 2:28 PM, Andrew Vit <[email protected]> wrote: > "first" and "last" have always returned an instance of the model. These > are meant to be the final method that you call on a relation, to get the > result. If you call "last(5)" it will return an array, and that's the > correct behaviour since that's the result of the query. If you need the > relation so you can add other criteria on top of it, you can still use > "limit(5).order(arel_table[:id].desc)" > > Andrew Vit > > > > On Wednesday, July 17, 2013 8:33:52 AM UTC-7, Robin Dupret wrote: >> >> Hello, >> >> Sorry if this has been still answered, I haven't found nothing on it. I >> would love to know why ActiveRecord::Base#last doesn't return an >> ActiveRecord::Relation just like all or where since an >> ActiveRecord::Relation can act more or less like an array (as specified >> here<https://github.com/rails/rails/commit/0a6833b6f701c8c8febadfe2f45e25df29493602> >> )? >> >> Thanks, have a nice day. >> > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rubyonrails-core. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
