InterviewSolution
| 1. |
Finding By Sql ? |
|
Answer» If you'd like to use your own SQL to find records in a table you can use find_by_sql. The find_by_sql method will return an array of objects even if the underlying query returns just a single record. For example you could run this query: Client.find_by_sql("SELECT * FROM CLIENTS INNER JOIN ORDERS ON clients.id = orders.client_id ORDER clients.created_at desc") find_by_sql provides you with a simple WAY of MAKING custom calls to the database and retrieving instantiated objects. If you'd like to use your own SQL to find records in a table you can use find_by_sql. The find_by_sql method will return an array of objects even if the underlying query returns just a single record. For example you could run this query: Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc") find_by_sql provides you with a simple way of making custom calls to the database and retrieving instantiated objects. |
|