Last active
December 14, 2015 21:19
-
-
Save skojin/5150548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecordSelectAttributesExtension | |
# Returns an array of arrays containing the field values. | |
# Order is the same as that returned by +columns+. | |
# select_rows("id, type") => [[1, 'one'], [2, 'one'], [3, 'two']] | |
def select_rows(fields = nil) | |
scope = fields ? self.scoped.select(fields) : self.scoped | |
connection.select_rows(scope.to_sql) | |
end | |
def select_attributes(fields = nil) | |
scope = fields ? self.scoped.select(fields) : self.scoped | |
connection.send(:select_all, scope.to_sql) | |
end | |
end | |
::ActiveRecord::Base.class_eval do | |
extend ActiveRecordSelectAttributesExtension | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment