Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:47:26+00:00 2026-06-11T16:47:26+00:00

For both basic conditions (like find statements) and the more general where clause, users

  • 0

For both basic conditions (like find statements) and the more general where clause, users have the ability to look for any of a group of conditions. For example:

User.find_by_name(["One", "Two", "Three"])
User.find_by_name_and_age(["One", "Two"],[1,2,3])

or

User.where(:bonus_id => [1,2,3])

Their is a slight inconsistance here, though. If you use

User.find_by_bonus_id([nil,1,2])

This will return uses with a bonus id of “nil”, as could be expected! However, both the “find_by_…and…” format and “where” format do NOT work this way.

User.where(:bonus_id => [nil,1])

Will return ONLY those Users with a bonus_id of 1.

User.where(:bonus_id => [nil]

will return nothing all!

User.where(:bonus_id => nil)

however, works fine.

As near as I can tell, the where clause (and find_by_and method) collapse their arrays, removing any values that are non-truthy. This is a pretty significant problem for me.

Does anyone know a way to include nils in a where clause array (or a workaround), or am I going to have to end up joining multiple queries together in order to obtain the right behaviour?

Additional Notes:
– Version 3.0.11
– Nils are not actually being dropped, but rather under certain circumstances it is comparing IN (NULL) instead of IS NULL in the SQL. I’m leaving the title as is, since even though it is inaccurate, it’s how the problem appears at first when encountered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:47:27+00:00Added an answer on June 11, 2026 at 4:47 pm

    I’m not able to reproduce your problem on Rails 3.1.0. What version are you using?

    Try this:

    User.where(["bonus_id IN (?) OR bonus_id IS NULL", [1,2]])
    

    Will return users where the bonus_id is either 1, 2, or null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

They're both resizable arrays, and std::basic_string doesn't have any specifically character-related functions like upper().
(Even more basic than Difference between Pig and Hive? Why have both? ) I
I have 2 basic forms: sign in and sign up, both on the same
I have a basic doubt that, How can we have both CLR's on a
I am new to both GAE and PiCould, and have some basic questions when
I have table structure like below: events (boxing, sparring etc) competitors (users who are
I have a WCF web service which allows both Basic HTTP and WS-HTTP clients,
I have a basic controller, just like this: class BookingController { def periodCheck(){ }
I'm trying to do a basic web page which uses both jQuery and MooTools.
I'm building a basic CRUD library, that I anticipate use in both local (add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.