File: //usr/local/rvm/gems/ruby-2.7.4/doc/activerecord-6.1.4.1/ri/ActiveRecord/Querying/find_by_sql-i.ri
U:RDoc::AnyMethod[iI"find_by_sql:ETI"'ActiveRecord::Querying#find_by_sql;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I"eExecutes a custom SQL query against your database and returns all the results. The results will ;TI"jbe returned as an array, with the requested columns encapsulated as attributes of the model you call ;TI"sthis method from. For example, if you call <tt>Product.find_by_sql</tt>, then the results will be returned in ;TI"Ka +Product+ object with the attributes you specified in the SQL query.;To:RDoc::Markup::BlankLine o;
; [I"cIf you call a complicated SQL query which spans multiple tables, the columns specified by the ;TI"bSELECT will be attributes of the model, whether or not they are columns of the corresponding ;TI"table.;T@o;
; [ I"aThe +sql+ parameter is a full SQL query as a string. It will be called as is; there will be ;TI"\no database agnostic conversions performed. This should be a last resort because using ;TI"idatabase-specific terms will lock you into using that particular database engine, or require you to ;TI",change your call if you switch engines.;T@o:RDoc::Markup::Verbatim; [I"3# A simple SQL query spanning multiple tables
;TI"aPost.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id"
;TI"]# => [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "author"=>"Quentin"}>, ...]
;T:@format0o;
; [I"rYou can use the same string replacement techniques as you can with <tt>ActiveRecord::QueryMethods#where</tt>:;T@o;; [I"jPost.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
;TI"~Post.find_by_sql ["SELECT body FROM comments WHERE author = :user_id OR approved_by = :user_id", { :user_id => user_id }];T;
0:
@fileI""lib/active_record/querying.rb;T:0@omit_headings_from_table_of_contents_below000[ I"/(sql, binds = [], preparable: nil, &block);T@)FI"
Querying;TcRDoc::NormalModule00