Permalink
Browse files

Adds support for instance level preload functionality

  • Loading branch information...
1 parent 90ff725 commit 7da1dffd0d13a26ead1a8601092a19fd3e7ccf76 @nesquena committed Nov 9, 2010
Showing with 14 additions and 1 deletion.
  1. +1 −1 init.rb
  2. +13 −0 lib/active_record_ext.rb
View
@@ -2,6 +2,6 @@
require 'array_ext'
# extend activerecord with the :preload method
-ActiveRecord::Base.send(:extend, AssociationsPreload::Base)
+ActiveRecord::Base.send(:include, AssociationsPreload::Base)
# add :preload method to array
Array.send(:include, AssociationsPreload::Array)
View
@@ -1,5 +1,18 @@
module AssociationsPreload
module Base
+ def self.included(base)
+ base.send(:include, AssociationsPreload::InstanceMethods)
+ base.send(:extend, AssociationsPreload::ClassMethods)
+ end
+ end
+
+ module InstanceMethods
+ def preload(*args)
+ self.class.preload(self, *args)
+ end
+ end
+
+ module ClassMethods
def preload(records, *args)
include_associations = send(:merge_includes, send(:scope, :find, :include), args)
preload_associations(records, include_associations) unless include_associations.empty?

0 comments on commit 7da1dff

Please sign in to comment.