From the course: Ruby on Rails 5 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Query methods: Order, limit, and offset - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
Query methods: Order, limit, and offset
- [Instructor] We've seen how to specify the conditions for our query, how to retrieve only the records that match a certain criteria, but there are three additional query methods that are helpful in allowing us to find exactly the records we want, and those are order, limit, and offset. Order is going to specify the sort order of the returned records. We can sort the records by any column, ID, name, position, created at, etc. We can sort them alphabetically, or reverse alphabetically, ascending, or descending, chronologically, or reverse chronologically. Limit will limit the results that are returned. This becomes especially important when there are a lot of records which match our conditions. Let's imagine that we have a database of 20,000 customers. We wouldn't want to see a page with all 20,000 customers at one time, we'd probably want to view them broken up as pages, maybe just 20 at a time. In that case, we would limit the results to 20. If we then wanted to view page 51 of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
ActiveRecord and ActiveRelation4m 32s
-
(Locked)
Model naming5m 52s
-
(Locked)
Model attributes2m 51s
-
(Locked)
The Rails console3m 17s
-
(Locked)
Create records4m 53s
-
(Locked)
Update records3m 16s
-
(Locked)
Delete records2m 29s
-
(Locked)
Find records5m 48s
-
(Locked)
Query methods: Conditions7m 39s
-
(Locked)
Query methods: Order, limit, and offset6m 29s
-
(Locked)
Named scopes8m 26s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-