Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameters sql query in find by sql

How to pass parameters sql query in find by sql

like image 918
Ritesh Choudhary Avatar asked Aug 30 '10 12:08

Ritesh Choudhary


1 Answers

The documentation explains it all. You do it like this, where author_id and start_date are the parameters passed in.

Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-find_by_sql

like image 66
Brendan Enrick Avatar answered Oct 16 '22 14:10

Brendan Enrick