This project is archived and is in readonly mode.

#3239 ✓wontfix
2 College Bums

add method to check if association is eager loaded

Reported by 2 College Bums | September 20th, 2009 @ 09:50 PM

To optimize sql queries for an application, it is helpful to see if associations that will be used are eager loaded. A simple method will allow users to easily check this. We implemented a version that would be helpful for other users.

class ActiveRecord::Base
  # Returns true if association has been eager loaded; false otherwise.
  # ex. model.eager_loaded?(:association)
  def eager_loaded?(association)
    !!self.instance_variable_get("@#{association}")
  end
end

Comments and changes to this ticket

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>

Pages