You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/active_record_querying.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,7 +244,7 @@ SELECT * FROM customers LIMIT 1
244
244
245
245
The `take` method returns `nil` if no record is found and no exception will be raised.
246
246
247
-
You can pass in a numerical argument to the `take` method to return up to that number of results. For example
247
+
You can pass in a numerical argument to the `take` method to return up to that number of results. For example:
248
248
249
249
```irb
250
250
irb> customers = Customer.take(2)
@@ -283,7 +283,7 @@ The `first` method returns `nil` if no matching record is found and no exception
283
283
284
284
If your [default scope](active_record_querying.html#applying-a-default-scope) contains an order method, `first` will return the first record according to this ordering.
285
285
286
-
You can pass in a numerical argument to the `first` method to return up to that number of results. For example
286
+
You can pass in a numerical argument to the `first` method to return up to that number of results. For example:
287
287
288
288
```irb
289
289
irb> customers = Customer.first(3)
@@ -361,7 +361,7 @@ SELECT * FROM customers ORDER BY customers.store_id DESC, customers.id DESC LIMI
361
361
362
362
If your [default scope](active_record_querying.html#applying-a-default-scope) contains an order method, `last` will return the last record according to this ordering.
363
363
364
-
You can pass in a numerical argument to the `last` method to return up to that number of results. For example
364
+
You can pass in a numerical argument to the `last` method to return up to that number of results. For example:
365
365
366
366
```irb
367
367
irb> customers = Customer.last(3)
@@ -978,7 +978,7 @@ Limit and Offset
978
978
979
979
To apply `LIMIT` to the SQL fired by the `Model.find`, you can specify the `LIMIT` using [`limit`][] and [`offset`][] methods on the relation.
980
980
981
-
You can use `limit` to specify the number of records to be retrieved, and use `offset` to specify the number of records to skip before starting to return the records. For example
981
+
You can use `limit` to specify the number of records to be retrieved, and use `offset` to specify the number of records to skip before starting to return the records. For example:
982
982
983
983
```ruby
984
984
Customer.limit(5)
@@ -1150,15 +1150,15 @@ Compare this to the case where the `reselect` clause is not used:
The Active Record pattern implements [Method Chaining](https://en.wikipedia.org/wiki/Method_chaining),
2136
-
which allow us to use multiple Active Record methods together in a simple and straightforward way.
2136
+
which allows us to use multiple Active Record methods together in a simple and straightforward way.
2137
2137
2138
2138
You can chain methods in a statement when the previous method called returns an
2139
2139
[`ActiveRecord::Relation`][], like `all`, `where`, and `joins`. Methods that return
@@ -2294,7 +2294,7 @@ irb> nina.save
2294
2294
Finding by SQL
2295
2295
--------------
2296
2296
2297
-
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:
2297
+
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:
2298
2298
2299
2299
```irb
2300
2300
irb> Customer.find_by_sql("SELECT * FROM customers INNER JOIN orders ON customers.id = orders.customer_id ORDER BY customers.created_at desc")
0 commit comments