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.

Fix that ActiveRecord would load a whole association when calling first

#1091

In some cases AssociationCollection would load the entire association, when just calling first or last. Example:


u = User.find(params[:id])

u.activities.last # Does a find(:last)

# Add something to the activities
u.activities.create!({:description => "List activities"})

u.activities.last # Fetches all activities of the user - Painfull when a user has 30000 activities

The patch included only does a full association load if there are records in the association that aren't saved.

Reported by Jan De Poorter · September 22nd, 2008 @ 05:01 PM

State: resolved
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Pratik
    • Title changed from [PATCH] Fix that ActiveRecord would load a whole association when calling first to Fix that ActiveRecord would load a whole association when calling first

    September 22nd, 2008 @ 05:02 PM

  2. Jan De Poorter
    Jan De Poorter
    • Assigned user cleared.
    • Title changed from Fix that ActiveRecord would load a whole association when calling first to [PATCH] Fix that ActiveRecord would load a whole association when calling first

    September 22nd, 2008 @ 05:08 PM

  3. Jan De Poorter
    Jan De Poorter
    • Assigned user set to Pratik
    • Title changed from [PATCH] Fix that ActiveRecord would load a whole association when calling first to Fix that ActiveRecord would load a whole association when calling first

    September 22nd, 2008 @ 05:08 PM

  4. Pratik
    Pratik

    Looks good.

    Getting one failing test though :

    
    HasAndBelongsToManyAssociationsTest)
        [./test/cases/associations/has_and_belongs_to_many_associations_test.rb:256:in `test_create'
         ./test/cases/../../../activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `__send__'
         ./test/cases/../../../activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `run']:
    <false> is not true.
    

    September 22nd, 2008 @ 05:33 PM

  5. Jan De Poorter
    Jan De Poorter

    Oops.. Fixed the tests so it reflects what I changed.

    September 22nd, 2008 @ 05:53 PM

  6. Repository
    Repository
    • State changed from new to resolved

    (from [050e58441bf7e60d167f6708072f8fa7aee2ce76]) Association#first and last should not load the association if not needed. [#1091 Fix that ActiveRecord would load a whole association when calling first state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    September 22nd, 2008 @ 06:23 PM