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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:59:49+00:00 2026-05-20T15:59:49+00:00

According to docs of ActiveRecord::Base : ==(comparison_object) Returns true if comparison_object is the same

  • 0

According to docs of ActiveRecord::Base:

==(comparison_object) Returns true if comparison_object is the same exact
object, or comparison_object is of the
same type and self has an ID and it is
equal to comparison_object.id.

Note that new records are different
from any other record by definition,
unless the other record is the
receiver itself. Besides, if you fetch
existing records with select and leave
the ID out, you’re on your own, this
predicate will return false.

Note also that destroying a record
preserves its ID in the model
instance, so deleted models are still
comparable.

But my observations show that it only compares instaces, not ids so that following are true:

a = Factory.create(:user)
b = User.find_by_email(a.email) # b is logically same as a

a.id.should == b.id # All good
a.should == b # FAILS: Contradicts the docs
a.should_not == b # Contradicts the docs
a.should_not eql b # Contradicts the docs

The question is 2 AR instances are considered to be different while the docs explicitly say that those should be equal?

UPDATE: The equality DOES work as expected. Code sample above is irrelevant. See my answer below.

  • 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-20T15:59:49+00:00Added an answer on May 20, 2026 at 3:59 pm

    Answering my own question (which is irrelevant).

    All the equality checks DO work as expected (and described in the docs).
    I assume the reason it did not work for me is that I run autotest and something could be cached or some other mythical reason that I can’t explain right now.

    To summarise, all the following assertions are indeed passing:

    a = Factory.create(:user)
    b = User.find_by_email(a.email) # b is logically same as a
    
    a.id.should == b.id
    a.should == b
    a.should eql b
    User.find_by_email(a.email).should == User.find_by_email(a.email)
    a.should == User.find_by_email(a.email)
    b.should == User.find_by_email(a.email)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the docs, super(cls, obj) returns a proxy object that delegates method calls
According to the docs any file type can now be uploaded to Google Docs,
According to the docs: (mc) mine-conflict - accept my version for all conflicts (same)
According to docs at http://code.google.com/p/minify/wiki/UriRewriting $min_serveOptions['rewriteCssUris'] = false; I should be able to add
According to the docs, jQuery.extend() is a solution to execute both a deep and
According to the docs , Array.include? uses the == comparison on objects. I come
According to the docs String text = String.format(%5.1e, 3.1415f); Should produce something like 3.1E+00
I'm using a System.Windows.Forms.TextBox . According to the docs, the MaxLength property controls the
I'm trying to decompress gzipped data with Inflater . According to the docs, If
According to the gcc docs , memcmp is not an intrinsic function of GCC.

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.