Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save taketo1113/04ea82bb16b619b70e084081082fb724 to your computer and use it in GitHub Desktop.
Save taketo1113/04ea82bb16b619b70e084081082fb724 to your computer and use it in GitHub Desktop.
How to write an ActiveRecord conditions not containing null or empty

ActiveRecord conditions not containing null or empty

> User.where.not(email: [nil, '']).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE (NOT ((\"users\".\"email\" = '' OR \"users\".\"email\" IS NULL)))"
  • env
    • ruby: 2.4.1
    • rails: 5.0.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment