For
more information about has_one, belongs_to, and the rest of the associations possible with
Active Record, see Chapter 4.
How Can You Paginate Active Record Results?
Paging through result sets is a very common database-related task. At the time of this writing,
Active Record has some limited support for pagination through the Action Controller library.
However, it??™s buggy, to say the least, and therefore, in the near future, pagination is expected to
be removed from this library and made available only as a plug-in to Active Record.
So our first recommendation would be to search for an Active Record pagination plug-in.
Failing that, you can always deal with pagination via a fancy use of SQL LIMIT clauses. In SQL
Server, for example, the following query allows you to get a subset of records you may want
(records 10??“20 here):
SELECT * FROM (SELECT TOP 10 * FROM (select top 20 * from comments order by id desc)
as tmp1 ORDER BY id asc) AS tmp2 ORDER BY id desc
CHAPTER 8 ?– ACTIVE RECORD AND THE REAL WORLD 213
Most every flavor of SQL supports some form of the TOP or LIMIT clause and can therefore
use a version of the preceding SQL statement.
Pages:
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484