aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMaurizio De Santis <desantis.maurizio@gmail.com>2013-02-07 22:43:50 +0100
committerMaurizio De Santis <desantis.maurizio@gmail.com>2013-02-07 22:50:08 +0100
commitba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c (patch)
tree30be2820928ebee51a7372d48221e2e4d62e01b7 /activerecord/lib
parenta8c2981f62555a7ea7e5b378509fca6009ba8a8e (diff)
downloadrails-ba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c.tar.gz
rails-ba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c.tar.bz2
rails-ba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c.zip
Add documentation for ActiveRecord.select when use strings as arguments
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 42849d6bc9..c025facbb9 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -189,6 +189,16 @@ module ActiveRecord
# 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>:
#