File: //usr/local/rvm/gems/ruby-3.0.2/doc/activerecord-6.1.4.1/ri/ActiveRecord/QueryMethods/select-i.ri
U:RDoc::AnyMethod[iI"select:ETI"&ActiveRecord::QueryMethods#select;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"Works in two unique ways.;To:RDoc::Markup::BlankLine o;
; [I"LFirst: takes a block so it can be used just like <tt>Array#select</tt>.;T@o:RDoc::Markup::Verbatim; [I"/Model.all.select { |m| m.field == value }
;T:@format0o;
; [I"JThis will build an array of objects from the database for the scope, ;TI"Dconverting them into an array and iterating through them using ;TI"<tt>Array#select</tt>.;T@o;
; [I"NSecond: Modifies the SELECT statement for the query so that only certain ;TI"fields are retrieved:;T@o;; [I"Model.select(:field)
;TI"-# => [#<Model id: nil, field: "value">]
;T;
0o;
; [I"MAlthough in the above example it looks as though this method returns an ;TI"Karray, it actually returns a relation object and can have other query ;TI"Umethods appended to it, such as the other methods in ActiveRecord::QueryMethods.;T@o;
; [I"?The argument to the method can also be an array of fields.;T@o;; [I"7Model.select(:field, :other_field, :and_one_more)
;TI"Z# => [#<Model id: nil, field: "value", other_field: "value", and_one_more: "value">]
;T;
0o;
; [I"YYou can also use one or more strings, which will be used unchanged as SELECT fields.;T@o;; [I"DModel.select('field AS field_one', 'other_field AS field_two')
;TI"C# => [#<Model id: nil, field: "value", other_field: "value">]
;T;
0o;
; [I"QIf an alias was specified, it will be accessible from the resulting objects:;T@o;; [I"8Model.select('field AS field_one').first.field_one
;TI"# => "value"
;T;
0o;
; [I"UAccessing attributes of an object that do not have fields retrieved by a select ;TI"?except +id+ will throw ActiveModel::MissingAttributeError:;T@o;; [I",Model.select(:field).first.other_field
;TI"L# => ActiveModel::MissingAttributeError: missing attribute: other_field;T;
0:
@fileI"0lib/active_record/relation/query_methods.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(*fields);T@DTI"QueryMethods;TcRDoc::NormalModule00