This project is archived and is in readonly mode.
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
-
CancelProfileIsBroken September 25th, 2009 @ 11:56 AM
- Tag changed from active_record, association, associations, associations_preload to active_record, association, associations, associations_preload, bugmash
-
Elad Meidar September 27th, 2009 @ 07:31 PM
+1 might come useful around tests, more than in a production environment. i've attached patches for 2-3-stable and master.
-
Elad Meidar September 27th, 2009 @ 07:34 PM
- Tag changed from active_record, association, associations, associations_preload, bugmash to active_record, association, associations, associations_preload, bugmash-review
-
Michael Koziarski September 28th, 2009 @ 02:44 AM
- State changed from new to wontfix
- Tag changed from active_record, association, associations, associations_preload, bugmash-review to active_record, association, associations, associations_preload
We already have a method for determining whether a collection was loaded
foo.bars.loaded?
Seems this is a subset of that?
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>