From ba407c8f7b8ca48d9f20318d23b60b32d2cd6b9c Mon Sep 17 00:00:00 2001 From: Maurizio De Santis Date: Thu, 7 Feb 2013 22:43:50 +0100 Subject: Add documentation for ActiveRecord.select when use strings as arguments --- activerecord/lib/active_record/relation/query_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib') 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) # # => [#] # + # 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') + # # => [#] + # + # 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 ActiveModel::MissingAttributeError: # -- cgit v1.2.3