This project is archived and is in readonly mode.
Fix that ActiveRecord would load a whole association when calling first
Reported by Jan De Poorter | September 22nd, 2008 @ 05:01 PM | in 2.x
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.
Comments and changes to this ticket
-
Pratik September 22nd, 2008 @ 05:02 PM
- 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
-
Jan De Poorter September 22nd, 2008 @ 05:08 PM
- 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
-
Jan De Poorter September 22nd, 2008 @ 05:08 PM
- 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
-
Pratik September 22nd, 2008 @ 05:33 PM
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.
-
Jan De Poorter September 22nd, 2008 @ 05:53 PM
Oops.. Fixed the tests so it reflects what I changed.
-
Repository September 22nd, 2008 @ 06:23 PM
- State changed from new to resolved
(from [050e58441bf7e60d167f6708072f8fa7aee2ce76]) Association#first and last should not load the association if not needed. [#1091 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1091 Fix that ActiveRecord would load a whole association when calling first (from [050e58441bf7e60d167f6708072f8fa7aee2ce76]) Associa...