Created
July 1, 2011 14:09
-
-
Save chudler/1058612 to your computer and use it in GitHub Desktop.
Empty Associations when eager loading using offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reviewer < ActiveRecord::Base | |
has_many :accounts | |
end | |
class Account < ActiveRecord::Base | |
belongs_to :reviewer | |
end | |
> Reviewer.where(:lastname => 'bloe', :firstname => 'joe').all(:offset => 0, :include => :accounts).first.accounts.present? | |
=> false # not true | |
Reviewer.where(:lastname => 'bloe', :firstname => 'joe').all(:include => :accounts).first.accounts.present? | |
=> true # it made N+1 query! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment