Permalink
Browse files

Add documentation for ActiveRecord.select when use strings as arguments

  • Loading branch information...
1 parent a8c2981 commit ba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c @mdesantis mdesantis committed Feb 7, 2013
Showing with 10 additions and 0 deletions.
  1. +10 −0 activerecord/lib/active_record/relation/query_methods.rb
@@ -189,6 +189,16 @@ def references!(*args) # :nodoc:
# Model.select(:field, :other_field, :and_one_more)
# # => [#<Model field: "value", other_field: "value", and_one_more: "value">]
#
+ # You can also use one or more strings, which will be used unchanged as SELECT fields.
+ #
+ # Model.select('field AS field_one', 'other_field AS field_two')
+ # # => [#<Model field: "value", other_field: "value">]
+ #
+ # If an alias was specified, it will be accessible from the resulting objects:
+ #
+ # Model.select('field AS field_one').first.field_one
+ # # => "value"
+ #
# Accessing attributes of an object that do not have fields retrieved by a select
# will throw <tt>ActiveModel::MissingAttributeError</tt>:
#

0 comments on commit ba407c8

Please sign in to comment.