When I use Model.find(:last) I get an error saying that it can''t find an ID=last. How come? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jul 24, 2008 at 3:25 PM, Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > When I use Model.find(:last) I get an error saying that it can''t find an > ID=last. How come?There is no Model.find(:first). You need to do Model.find(:first, :order => ''?? DESC'')> -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Justin To wrote:> Pål Bergström wrote: >> When I use Model.find(:last) I get an error saying that it can''t find an >> ID=last. How come? > > Do you have a column "id" or something to index with? > > Maybe, try find_by_id or find_by_column-name(:last)Not sure what you mean. I have and id, yes. I''m just trying to find that last record with :last, the opposite to :first. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 2008-07-24 at 22:25 +0200, Pål Bergström wrote:> When I use Model.find(:last) I get an error saying that it can''t find an > ID=last. How come?---- not an implemented option http://rails.rubyonrails.org/classes/ActiveResource/Base.html#M000933 Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pål Bergström wrote:> When I use Model.find(:last) I get an error saying that it can''t find an > ID=last. How come?There''s no option :last. Instead, find(:first) but specify an order to reverse them. For example: Model.find(:first, :order => ''created_at desc'') This will fetch the most recently created item. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Weiskotten wrote:> Pål Bergström wrote: >> When I use Model.find(:last) I get an error saying that it can''t find an >> ID=last. How come? > > There''s no option :last. Instead, find(:first) but specify an order to > reverse them. For example: > > Model.find(:first, :order => ''created_at desc'') > > This will fetch the most recently created item.Hmm. From the api: # find last Person.find(:last) # returns the last object fetched by SELECT * FROM people Person.find(:last, :conditions => [ "user_name = ?", user_name]) Person.find(:last, :order => "created_on DESC", :offset => 5) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White wrote:> On Thu, 2008-07-24 at 22:25 +0200, Pål Bergström wrote: >> When I use Model.find(:last) I get an error saying that it can''t find an >> ID=last. How come? > ---- > not an implemented option > > http://rails.rubyonrails.org/classes/ActiveResource/Base.html#M000933 > > CraigI understand. Why is it in there? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 2008-07-24 at 23:40 +0200, Pål Bergström wrote:> Craig White wrote: > > On Thu, 2008-07-24 at 22:25 +0200, Pål Bergström wrote: > >> When I use Model.find(:last) I get an error saying that it can''t find an > >> ID=last. How come? > > ---- > > not an implemented option > > > > http://rails.rubyonrails.org/classes/ActiveResource/Base.html#M000933 > > > > Craig > > I understand. Why is it in there?---- with optional arguments it works, without optional arguments, it fails...>> Personnel.find :lastActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax for integer: "--- :last " : SELECT * FROM personnels WHERE (personnels."id" = ''--- :last '') at least it fails with postgres...perhaps some of the SQL adaptors can make sense of the query Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Weiskotten wrote:> Interesting, that was added in March. What version of Rails are you > using? I''m guessing you need 2.1.I see. I run 2.0.2. That explains it. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Even if you''re using a version of Rails that doesn''t have the find(:last) option, you can essentially pull of the same thing with: find(:first, :order => ''id desc'') I think that may even be what the Rails method does. -- Josh Jeremy Weiskotten wrote:>> >> at least it fails with postgres...perhaps some of the SQL adaptors can >> make sense of the query >> >> Craig > > Working for me with postgres 8.3.1 with or without options.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Abbott wrote:> Even if you''re using a version of Rails that doesn''t have the > find(:last) option, you can essentially pull of the same thing with: > > find(:first, :order => ''id desc'') > > I think that may even be what the Rails method does. > > -- JoshYes, I know. I normally use that. Then I saw :last in the api. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
With me Model.first works... Model.last works as well... no need for Model.find... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---