Created
February 25, 2017 03:23
-
-
Save mmmpa/f04d5b870e8c04b2ac1615f05d33b0e4 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
def pluck(*column_names) | |
if loaded? && (column_names.map(&:to_s) - @klass.attribute_names - @klass.attribute_aliases.keys).empty? | |
return records.pluck(*column_names) | |
end | |
if has_include?(column_names.first) | |
construct_relation_for_association_calculations.pluck(*column_names) | |
else | |
relation = spawn | |
relation.select_values = column_names.map { |cn| | |
@klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn | |
} | |
result = klass.connection.select_all(relation.arel, nil, bound_attributes) | |
result.cast_values(klass.attribute_types) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
activerecord/lib/active_record/relation/calculations.rb