Created
May 1, 2012 19:30
-
-
Save Veejay/2570724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :for_project_and_date_range, lambda { |project, lower, upper| | |
if lower.cweek < upper.cweek | |
where(project_id: project.id, year: lower.year, cweek: Range.new(lower.cweek,upper.cweek)) | |
else # The date range spans over two years | |
query = "project_id = ? AND ((cweek > ? AND year = ?) OR (cweek < ? AND year = ?))" | |
where(query, project.id, lower.cweek, lower.year, upper.cweek, upper.year) | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment