On 14 July 2010 15:22, Max Williams <[email protected]> wrote: > Can anyone give me the sql for this? I can't quite figure it out. I > want to find the most recent record from the states table that is before > a given date, and if that doesn't exist, the first one *after* that > date?
Do you mean date or datetime? In other words what about about any on the given date? If you mean datetime then there could still be one exactly at that time. Your spec says that this one should not be found, is that correct? Colin > > Currently i'm doing it as two seperate finds, like this, but i need to > combine it into one sql call if i can. > > self.states.find(:first, :conditions => ["created_at < ?", time], > :order => "created_at desc") || > self.states.find(:first, :conditions => ["created_at > ?", > time], :order => "created_at") > > thanks, max > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

