aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_querying.md
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2014-06-28 13:54:24 -0500
committerschneems <richard.schneeman@gmail.com>2014-06-28 17:49:40 -0500
commite9f04cdb6b3814b33ced289000e496416f894ee1 (patch)
treedcdfd815ad90d4eaf5f37c53ecf306362d0db0fb /guides/source/active_record_querying.md
parent13770587ef7f909e53a000bfae790f92576a3d93 (diff)
downloadrails-e9f04cdb6b3814b33ced289000e496416f894ee1.tar.gz
rails-e9f04cdb6b3814b33ced289000e496416f894ee1.tar.bz2
rails-e9f04cdb6b3814b33ced289000e496416f894ee1.zip
[ci skip] Add return values to examples
Diffstat (limited to 'guides/source/active_record_querying.md')
-rw-r--r--guides/source/active_record_querying.md11
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`