Skip to content

Instantly share code, notes, and snippets.

@chudler
Created July 1, 2011 14:09
Show Gist options
  • Save chudler/1058612 to your computer and use it in GitHub Desktop.
Save chudler/1058612 to your computer and use it in GitHub Desktop.
Empty Associations when eager loading using offset
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