0
votes

I have the following code (which is not working as I would like)

def self.from_omniauth(auth)
where(auth.slice(:provider, :uid) || auth.info.slice(:email)).first_or_initialize.tap do |user|
  user.provider = auth.provider
  user.uid = auth.uid
  user.name = auth.info.name
  user.email = auth.info.email
  user.oauth_token = auth.credentials.token
  user.oauth_expires_at = Time.at(auth.credentials.expires_at)
  if user.password = ""
    temp_pass = SecureRandom.urlsafe_base64
    user.password = temp_pass
    user.password_confirmation = temp_pass
  end
  user.save!
end

end

What I am trying to create is a activerecord where clause such as:

User.where("provider = ? AND uid = ? OR email = ?", "facebook",    "1569037127","[email protected]")

The SQL that is generated when this code is executed does not include the OR statement, or any reference to the email field.

User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."provider" = 'facebook' AND "users"."uid" = '100007760885613' ORDER BY "users"."id" ASC LIMIT 1

Any help with this would be fantastic...

1

1 Answers

0
votes

It's because you're telling it to do this or that, not have a query with and or in.

Why can't you do:

where("provider = ? AND uid = ? OR email = ?", auth["provider"], auth["uid"], auth["info"]["email"])

Pretty much as you had below that?