Advanced scope (or how to optimize it.)

Hi all,

I have a question about my scope in Rails 3.0. The following code working fine but I thinks it's not clean and could be optimzed.

What do you think about that :

scope :between_date, lambda { |start_at, end_at| {:conditions => ["((start_at BETWEEN ? AND ?) AND (end_at BETWEEN ? AND ?)) OR (all_day = 1 AND ((start_at BETWEEN ? AND ?) AND (end_at BETWEEN ? AND ?)))", start_at, end_at, start_at, end_at, start_at.beginning_of_day, end_at.end_of_day, start_at.beginning_of_day, end_at.end_of_day]} }

(http://pastie.org/1266339)

I have found the first part of the solution, but I don't know how scope can aggragate "all_day condition" to this condition.

{:conditions => { :start_at => start_at..end_at, :end_at => start_at..end_at }}

Thanks for reading

vincent