Module: Pluckers::Features::Pluck
- Includes:
- Base::Pluck
- Included in:
- Base
- Defined in:
- lib/pluckers/features/active_record_3_2/pluck.rb,
lib/pluckers/features/active_record_4_0/pluck.rb,
lib/pluckers/features/active_record_4_1/pluck.rb,
lib/pluckers/features/active_record_4_2/pluck.rb,
lib/pluckers/features/active_record_5_0/pluck.rb,
lib/pluckers/features/active_record_5_1/pluck.rb
Instance Method Summary collapse
- #all_method ⇒ Object
-
#pluck_records(*fields_to_pluck) ⇒ Object
In ActiveRecord 3.2 pluck only accepts one column.
Instance Method Details
#all_method ⇒ Object
21 22 23 |
# File 'lib/pluckers/features/active_record_3_2/pluck.rb', line 21 def all_method :scoped end |
#pluck_records(*fields_to_pluck) ⇒ Object
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/
10 11 12 13 14 15 16 17 18 19 |
# 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 |