I am doing some plain SQLs in my rails model (for purists this is just for complex SQLs 🙂
Since I am not using find*/condition methods, is there a helper method that I can use straight to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
quotemethod on the connection object escapes strings. When building up queries, usesanitize_sql_for_conditionsto convert ActiveRecord conditions hashes or arrays to SQL WHERE clauses.The methods in
ActiveRecord::ConnectionAdapters::DatabaseStatementsare handy for direct queries, in particular the ones starting withselect_.