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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:40:16+00:00 2026-06-17T08:40:16+00:00

I am upgrading a project from Rails 2.3.2 to 2.3.15. It appears that exists?

  • 0

I am upgrading a project from Rails 2.3.2 to 2.3.15. It appears that exists? may now be considered a finder, which means functions such as after_find are now callbacks from exists?.

In 2.3.2 exists? did not trigger a callback to after_find. I am having trouble finding a readable changelog other than commits on github which explicitly names this change in policy.

Can someone confirm that exists? did not call after_find (should it be present) in 2.3.2 and it does in 2.3.15?

If this is the case, is there a clean Rails way to segregate the after_find call? I need some code executed after a true find, not after an exists?.

As a temporary work-around, I am experimenting with making this the first line in my model’s after_find:

return unless self.has_attribute?(:some_attrib_your_model_uses_in_after_find)
  • 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-17T08:40:17+00:00Added an answer on June 17, 2026 at 8:40 am

    There are three ways to do this that I’ve found, none of them satisfactory but at least two of them will work reliably, even if they’re surprising in design and can create some very subtle bugs down the road.

    A) Return if an Attribute You’ll Use is Missing

    def after_find
      # What a flaky way to ruin your code:
      return unless self.has_attribute?(:some_attrib_your_model_uses_in_after_find)
      @amazing_pain = @some_attrib_your_model_uses_in_after_find + 1
    end
    

    B) Grep the Entire Callstack

    (and pray exists? is in there because you think it is)

    I’m ashamed to post this as an option, but it’s good to see what you can do with the array of strings available to caller. Let’s just hope caller doesn’t change the formatting.

    Using 2.3.15 from the console, the callstack to my model’s after_find() is:

    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/callbacks.rb:347:in `send'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/callbacks.rb:347:in `callback'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:1687:in `send'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:1687:in `instantiate'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:665:in `find_by_sql'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:665:in `collect!'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:665:in `find_by_sql'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:1582:in `find_every'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:1539:in `find_initial'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.15/lib/active_record/base.rb:696:in `exists?'
    (irb):2:in `irb_binding'
    /usr/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
    /usr/lib/ruby/1.8/irb/workspace.rb:52
    

    C) Make the Model Eager-Load

    Some people might want to do this, an the 2.3.15 ActiveRecord README hints at it:

    after_find :eager_load, 'self.class.announce(#{id})'
    

    I don’t want to put any more burden on the DB than I must. The point of calling exists? in many cases is to do a simple single-column lookup. Performing eager loading of a whole model and potentially its associations just to do an exists? call is going to cause a performance hit.

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

Sidebar

Related Questions

After upgrading a project from Flex4 Beta1 to Beta2, I've found that the background-image
I have an NServicebus project that I cannot start after upgrading from 2.6 to
I'm on a project upgrading from Rails 2 -> 3. We are removing Ultrasphinx
A quick and easy answer I'm sure. I'm upgrading a Rails project from version
After upgrading a working project from EF 4.0 to 4.1, I am now receiving
I'm upgrading a project to Rails 3.1 and Jruby 1.6.4 from rails 2.6 I
I have a project that I'm upgrading from 2008 to 2010. My problem is
I'm working on upgrading my project from rails 3.0.9 to rails 3.2.5. I'm using
We're upgrading a project from Sitefinity 3.7 to 4.4 and some of our controls
I'm looking at upgrading a POS (Point Of Sale) project which is currently built

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.