Skip to content

Instantly share code, notes, and snippets.

@dyatlov

dyatlov/task.rb Secret

Created January 6, 2015 13:15
Show Gist options
  • Save dyatlov/6fcf619bad1ff08f1ebc to your computer and use it in GitHub Desktop.
Save dyatlov/6fcf619bad1ff08f1ebc to your computer and use it in GitHub Desktop.
def self.unanswered_with_max(user, task)
joins("LEFT OUTER JOIN answers a ON a.input_id=inputs.id \
AND a.user_id=#{user.id}")
.joins('LEFT OUTER JOIN input_allocations ON input_allocations.input_id='\
'inputs.id AND input_allocations.expires_at>\'' + Time.now.to_s + '\'')
.where('a.id IS NULL')
.where(task_id: task.id)
.group('inputs.id,input_allocations.input_id')
.having('COUNT(input_allocations.input_id)+answers_count<?',
task.max_answers)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment