The NULL value can be surprising until you get used to it. Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values.
You cannot compare null using equal to for this you must use IS NULL. So update your queries to
Customer.includes(:orders, :shipping_address).where('customers.shipping_address_id IS NULL')
Or rails way of doing this is
Customer.where(shipping_address_id: nil).includes(:orders, :shipping_address)