Created
October 18, 2013 18:47
-
-
Save jcutrell/7046200 to your computer and use it in GitHub Desktop.
The goal of the query is to select all users who do not have assignments within a range.
The range is defined on the assignment model, so this would be in assignment.rb in a rails project
Startdatetime and enddatetime are attributes on the Assignment model.
This file contains hidden or 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
User.joins(:assignments).where.not("(assignments.startdatetime > ? AND assignments.startdatetime < ?) OR (assignments.enddatetime < ? AND assignments.enddatetime > ?)", startdatetime, enddatetime, startdatetime, enddatetime) | |
# This would be fine, except it does not include users who do not have assignments at all. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment