module Pluckers::Features::Pluck
Public Instance Methods
all_method()
click to toggle source
# File lib/pluckers/features/active_record_3_2/pluck.rb, line 21 def all_method :scoped end
pluck_records(*fields_to_pluck)
click to toggle source
In ActiveRecord 3.2 pluck only accepts one column. We have to go around it and not actually use the pluck method.
Idea based on meltingice.net/2013/06/11/pluck-multiple-columns-rails/
# File lib/pluckers/features/active_record_3_2/pluck.rb, line 10 def pluck_records(*fields_to_pluck) records_clone = @records.clone records_clone.select_values = fields_to_pluck @records.connection.select_all(records_clone.arel).map do |attributes| initialized_attributes = @records.klass.initialize_attributes(attributes) attributes.each do |key, attribute| attributes[key] = @records.klass.type_cast_attribute(key, initialized_attributes) end end end