Skip to content

Instantly share code, notes, and snippets.

@skojin
Last active December 14, 2015 21:19
Show Gist options
  • Save skojin/5150548 to your computer and use it in GitHub Desktop.
Save skojin/5150548 to your computer and use it in GitHub Desktop.
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