Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of code

  • Loading branch information...
commit f075db21d1c202084eb68e9c3efee3ef616d7680 0 parents
@nesquena authored
0  README.md
No changes.
7 init.rb
@@ -0,0 +1,7 @@
+require 'active_record_ext'
+require 'array_ext'
+
+# extend activerecord with the :preload method
+ActiveRecord::Base.send(:extend, AssociationsPreload::Base)
+# add :preload method to array
+Array.send(:include, AssociationsPreload::Array)
9 lib/active_record_ext.rb
@@ -0,0 +1,9 @@
+module AssociationsPreload
+ module Base
+ def preload(records, *args)
+ include_associations = send(:merge_includes, send(:scope, :find, :include), args)
+ preload_associations(records, include_associations) unless include_associations.empty?
+ records
+ end
+ end
+end
8 lib/array_ext.rb
@@ -0,0 +1,8 @@
+module AssociationsPreload
+ module Array
+ def preload(*args)
+ return self if self.empty?
+ first.class.preload(self, *args)
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.