Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base#exists? raises exception when using :include in default_scope

#5801

When using default_scope containing :include, ActiveRecord::Base#exists? raises a ActiveRecord::MissingAttributeError.

A demonstration of the error for ActiveRecord 2.3.9 is available here:

http://gist.github.com/624421/4735425e696993b7d409c7cb8b77878461712881

A demonstration of the error for ActiveRecord 3.0.0 is available here:

https://gist.github.com/624421/417c372a474a16566989261c8e0f9944fe32...

Neither of these are proper automated test cases, but it should be possible to fit them into ActiveRecord's test suite without too much difficulty.

This error appears to be related to the change introduced by #2543 Make ActiveRecord::Base.exists? invoke find_initial to support :include scopes. Robin Salkeld's comment on #2543 Make ActiveRecord::Base.exists? invoke find_initial to support :include scopes (https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets...) seems especially relevant.

Reported by yipdw · October 13th, 2010 @ 06:10 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. yipdw
  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete
    • Importance changed from to Low

    Please attach a patch with a failing test to this ticket by following the "Contributing to Rails" guide.

    http://guides.rubyonrails.org/contributing_to_rails.html

    October 13th, 2010 @ 09:39 PM

  3. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:27 AM

  4. Jonathan Julian
    Jonathan Julian

    This also raises when exists? is called on an association with an :include. Note that it only raises when it should return true. ActiveRecord 3.0.2

    A workaround, if you can use an id to check for existence:

    model.collection_singular_ids.include?(associated_id)
    

    November 18th, 2010 @ 04:35 AM

  5. rails
    rails
    • State changed from incomplete to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    March 29th, 2011 @ 01:00 AM

  6. rails
    rails
    • State changed from open to stale

    March 29th, 2011 @ 01:00 AM