I have a set of dates in my database and would like to only get the latest one or the one closest to the current date. I''m trying to come up with a way of doing it but had no luck. If any one could help I would appreciate 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 -~----------~----~----~----~------~----~------~--~---
Sort by date with a limit of one? Hopefully you have an index on that field? On Jan 19, 8:54 am, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a set of dates in my database and would like to only get the > latest one or the one closest to the current date. I''m trying to come up > with a way of doing it but had no luck. If any one could help I would > appreciate it. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
David Medinets wrote:> Sort by date with a limit of one? Hopefully you have an index on that > field? > > On Jan 19, 8:54�am, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>forgot to mention that I''m using thinking sphinx as a search engine my statement looks like this @allRooms = Room.search :conditions => {:created_at => here is where I should have a statement} -- 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 -~----------~----~----~----~------~----~------~--~---
You can do this in ActiveRecord is Room.find :first, :order => ''created_at desc'' See http://ts.freelancing-gods.com/rdoc/classes/ThinkingSphinx/Search.html#M000071for more about ordering search results, which is really what you want. I don''t think the AR flavor I gave above is likely to work out of the box with the Sphinx #search method. However, you could probably just ignore the Sphinx part if you really just want the most recently-created record of your rooms table, and let AR retrieve it for you. On Mon, Jan 19, 2009 at 9:40 AM, Sam Ginko <rails-mailing-list-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> > David Medinets wrote: > > Sort by date with a limit of one? Hopefully you have an index on that > > field? > > > > On Jan 19, 8:54�am, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > forgot to mention that I''m using thinking sphinx as a search engine my > statement looks like this > > @allRooms = Room.search :conditions => {:created_at => here is where I > should have a statement} > -- > 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 -~----------~----~----~----~------~----~------~--~---