Better yet. Take these conditions and apply each as a named scope. Then, by chaining the calls you'll get everything in one nice little query. So for example (assuming a default order of: "id ASC"): In your model (lets call it Foo):
named_scope :for_status, lambda { |status| { :conditions => { :status => status } } } named_scope :find_previous, lambda { |id| { :conditions => [ "id < :id", { :id => id } ] } } named_scope :find_subsequent, lambda { |id| { :conditions => [ "id > :id", { :id => id } ] } } Then to fetch the desired record you can do this: previous = Foo.for_status(true).find_previous(3).first next = Foo.for_status(true).find_subsequent(1).last Cheers, Tim On Wed, Sep 23, 2009 at 7:35 AM, Marnen Laibow-Koser < rails-mailing-l...@andreas-s.net> wrote: > > Mike Mickey wrote: > > thanks colin and rob, that's approximately what I have so far, > > I was hoping a solution to do it in one request :-/ > > > > The simplest way would be to use UNION on the two queries. You could > also use subquery syntax to munge the criteria. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > mar...@marnen.org > -- > Posted via http://www.ruby-forum.com/. > > > > -- Tim Lowrimore Coroutine LLC 516 Tennessee St., Suite 215 Memphis, TN 38103 office: 901.312.8818 mobile: 901.490.5325 http://www.coroutine.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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---