summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/user.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 924cb543fab..35f5ab56798 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -235,9 +235,18 @@ class User < ActiveRecord::Base
# Find a User by their primary email or any associated secondary email
def find_by_any_email(email)
- User.reorder(nil).
- where('id IN (SELECT user_id FROM emails WHERE email = :email) OR email = :email', email: email).
- take
+ # Arel doesn't allow for chaining operations on union nodes, thus we have
+ # to write this query by hand. See the following issue for more info:
+ # https://github.com/rails/arel/issues/98.
+ sql = '(SELECT * FROM users WHERE email = :email
+ UNION
+ SELECT users.*
+ FROM emails
+ INNER JOIN users ON users.id = emails.user_id
+ WHERE emails.email = :email)
+ LIMIT 1;'
+
+ User.find_by_sql([sql, { email: email }]).first
end
def filter(filter_name)