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 1113181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:49:05+00:00 2026-05-17T02:49:05+00:00

Using Rails 3 active relation, I have a scope: scope :duplicate_contact, lambda {|contact| where(

  • 0

Using Rails 3 active relation, I have a scope:

  scope :duplicate_contact, lambda {|contact| where(
                  :person_id          => contact.person_id,
                  :salutation         => contact.salutation,
                  :first_name         => contact.first_name,
                  :last_name          => contact.last_name,
                  :suffix             => contact.suffix,
                  :birthday           => contact.birthday,
                  :address            => contact.address,
                  :city               => contact.city,
                  :state              => contact.state,
                  :zip                => contact.zip,
                  :phone_1            => [contact.phone_1,contact.phone_2,contact.phone_3],
                  :phone_1_type       => [contact.phone_1_type,contact.phone_2_type,contact.phone_3_type],
                  :phone_2            => [contact.phone_1,contact.phone_2,contact.phone_3],
                  :phone_2_type       => [contact.phone_1_type,contact.phone_2_type,contact.phone_3_type],
                  :phone_3            => [contact.phone_1,contact.phone_2,contact.phone_3],
                  :phone_3_type       => [contact.phone_1_type,contact.phone_2_type,contact.phone_3_type],
                  :email              => [contact.email,contact.alternate_email],
                  :alternate_email    => [contact.email,contact.alternate_email]
            )
          }

This has a problem when :email is NULL. It returns back zero rows, when in fact it should return at least 1 row, ie duplicate_contact(contact).size == 0 is true when it should be false.

I think this has to do with this staement from the mysql docs: “In SQL, the NULL value is never true in comparison to any other value, even NULL.”

How can I get this to return the correct result?

  • 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-05-17T02:49:06+00:00Added an answer on May 17, 2026 at 2:49 am

    One possible solution that I found:

     scope :duplicate_contact, lambda {|contact| 
    
        q = where(
          :person_id          => contact.person_id,
          :salutation         => contact.salutation,
          :first_name         => contact.first_name,
          :last_name          => contact.last_name,
          :suffix             => contact.suffix,
          :birthday           => contact.birthday,
          :address            => contact.address,
          :city               => contact.city,
          :state              => contact.state,
          :zip                => contact.zip
        )
        [contact.phone_1,contact.phone_2,contact.phone_3].compact.each{|p| q=q.has_phone(p)}
        [contact.phone_1_type,contact.phone_2_type,contact.phone_3_type].compact.each{|p| q=q.has_phone_type(p)}
        [contact.email,contact.alternate_email].compact.each{|p| q=q.has_email(p)}
        q
      }
      scope :has_phone, lambda {|phone|
        where("'#{phone}' IN (phone_1,phone_2,phone_3)")
      }
      scope :has_phone_type, lambda {|phone|
        where("'#{phone}' IN (phone_1_type,phone_2_type,phone_3_type)")
      }
      scope :has_email, lambda {|email|
        where("'#{email}' IN (email,alternate_email)")
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails with Active Admin and I have one model
Hi I have been using the normal rails active record LIKE search in my
I'm using Rails 2.3.9. To illustrate the issue, suppose we have a named scope
Using Rails 3.1.0, with Active Scaffold (from the git repo). My controllers have code
Hi i am using rails and active record and there is some problem with
I am using Rails 3.1.3 with active admin gem. I am trying overwrite the
the active admin docs says: If you are using Rails >= 3.1, you must
When you're using a boolean in Rails with Active Record, and you ask (say)
Using Rails 3.2. I have an individual Shop post, and each shop has reviews.
I'm using Rails 3, ActiveAdmin and Kaminari. I have this on the documents.rb file

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.