Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. named_scope :between, lambda {|starting, ending|
  2. conditions = ['']
  3. conditions[0] += '(started_at > ? AND started_at < ?)'
  4. conditions << starting
  5. conditions << ending
  6. conditions[0] += ' OR (completed_at IS NULL AND stopped_at IS NULL AND end_at > ? AND end_at < ?)'
  7. conditions << starting
  8. conditions << ending
  9. conditions[0] += ' OR (completed_at IS NOT NULL AND completed_at > ? AND completed_at < ?)'
  10. conditions << starting
  11. conditions << ending
  12. conditions[0] += ' OR (stopped_at IS NOT NULL AND stopped_at > ? AND stopped_at < ?)'
  13. conditions << starting
  14. conditions << ending
  15. {:conditions => conditions}
  16. }
Add Comment
Please, Sign In to add comment