Skip to content

Make CollectionAssociation first/last with integer fetch with query#12137

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
lann:fix_association_first_last
Sep 12, 2013
Merged

Make CollectionAssociation first/last with integer fetch with query#12137
rafaelfranca merged 1 commit into
rails:masterfrom
lann:fix_association_first_last

Conversation

@lann

@lann lann commented Sep 4, 2013

Copy link
Copy Markdown
Contributor

When first or last is called with an integer on an unloaded association,
the entire collection is loaded. This differs surprisingly from the
behavior of Relation#first/last, which translate the call into a limit
query. For large collections this can make a big difference in
performance.

Change CollectionAssociation#fetch_first_or_last_using_find? to make
this kind of call delegate to Relation.

@robin850

robin850 commented Sep 7, 2013

Copy link
Copy Markdown
Member

Thanks for your contribution! Could you please add a changelog entry ?

When first or last is called with an integer on an unloaded association,
the entire collection is loaded. This differs surprisingly from the
behavior of Relation#first/last, which translate the call into a limit
query. For large collections this can make a big difference in
performance.

Change CollectionAssociation#fetch_first_or_last_using_find? to make
this kind of call delegate to Relation.
@lann

lann commented Sep 10, 2013

Copy link
Copy Markdown
Contributor Author

@robin850 Changelog updated.

rafaelfranca added a commit that referenced this pull request Sep 12, 2013
Make CollectionAssociation first/last with integer fetch with query

Conflicts:
	activerecord/CHANGELOG.md
@rafaelfranca rafaelfranca merged commit 8875e28 into rails:master Sep 12, 2013
@rafaelfranca

Copy link
Copy Markdown
Member

Make sense. Thanks

@lann lann deleted the fix_association_first_last branch September 13, 2013 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants