Skip to content

Instantly share code, notes, and snippets.

@simonista
Created February 16, 2012 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonista/1848627 to your computer and use it in GitHub Desktop.
Save simonista/1848627 to your computer and use it in GitHub Desktop.
if connection.adapter_name =~ /mysql/i
connection.execute <<-SQL
UPDATE users, conversation_participants cp
SET unread_conversations_count = unread_conversations_count + 1
WHERE users.id = cp.user_id AND #{cp_conditions}
SQL
else
User.update_all 'unread_conversations_count = unread_conversations_count + 1',
"id IN (SELECT user_id FROM conversation_participants cp WHERE #{cp_conditions})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment