diff options
author | schneems <richard.schneeman@gmail.com> | 2014-06-28 13:54:24 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2014-06-28 17:49:40 -0500 |
commit | e9f04cdb6b3814b33ced289000e496416f894ee1 (patch) | |
tree | dcdfd815ad90d4eaf5f37c53ecf306362d0db0fb | |
parent | 13770587ef7f909e53a000bfae790f92576a3d93 (diff) | |
download | rails-e9f04cdb6b3814b33ced289000e496416f894ee1.tar.gz rails-e9f04cdb6b3814b33ced289000e496416f894ee1.tar.bz2 rails-e9f04cdb6b3814b33ced289000e496416f894ee1.zip |
[ci skip] Add return values to examples
-rw-r--r-- | guides/source/active_record_querying.md | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 486e7b80ff..69d6205715 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1487,6 +1487,11 @@ If you'd like to use your own SQL to find records in a table you can use `find_b Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER BY clients.created_at desc") +# => [ + #<Client id: 1, first_name: "Lucas" >, + #<Client id: 2, first_name: "Jan" >, + # ... +] ``` `find_by_sql` provides you with a simple way of making custom calls to the database and retrieving instantiated objects. @@ -1496,7 +1501,11 @@ Client.find_by_sql("SELECT * FROM clients `find_by_sql` has a close relative called `connection#select_all`. `select_all` will retrieve objects from the database using custom SQL just like `find_by_sql` but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record. ```ruby -Client.connection.select_all("SELECT * FROM clients WHERE id = '1'") +Client.connection.select_all("SELECT first_name, created_at FROM clients WHERE id = '1'") +# => [ + {"first_name"=>"Rafael", "created_at"=>"2012-11-10 23:23:45.281189"}, + {"first_name"=>"Eileen", "created_at"=>"2013-12-09 11:22:35.221282"} +] ``` ### `pluck` |