Manipulating loadAll and loadArrayBy Results

All code generated loadAll() and loadArrayBy...() methods accept an optional QCubed Query Clause Array parameter, where you can specify a Clause objects, including functionality that handles ORDER BY, LIMIT and Object Expansion. We will discuss Object Expansion in the examples that deal with Late Binding and Early Binding. But for this example, we'll focus on using QQ::orderBy() and QQ::limitInfo() to manipulate how the results come out of the database.

orderBy() and limitInfo() are straightforward to use. OrderBy takes in any number of QCubed Query Node columns, followed by an optional boolean (to specify ascending/descending), which will be used in a SQL ORDER BY clause in the SELECT statement. So you can simply say \QCubed\Query\QQ::OrderBy(QQN::Person()->LastName) to sort all the Person objects by last name.

limitInfo() accepts a maximum row count, followed by an optional offset. So if you specified "10, 4", the result set would contain at most 10 rows, starting with row #5 (the offset is based on a 0 index).

You can use either, both, more or none of these optional Clause parameters whenever you make your loadAll() or loadArrayBy() calls. In the section about DataGrids, you will learn how to take sort and limit information from a DataGrid to populate the DataGrid with the data the user is asking for, in the order of the sort column.

For more information about "QQ::"-related classes (a.k.a. QCubed Query), please refer to section 3 of the Examples Site.

List All Persons, Ordered by LastName then FirstName

Brady, Linda (ID #9)
Carlisle, Brett (ID #11)
Doe, John (ID #1)
Ho, Mike (ID #4)
Jones, Samantha (ID #8)
Pratt, Jacob (ID #12)
Public, Kendall (ID #2)
Robinson, Ben (ID #3)
Smith, Alex (ID #5)
Smith, Jennifer (ID #10)
Smith, Wendy (ID #6)
Wolfe, Karen (ID #7)

List Five People, Start with the Third from the Top, Ordered by Last Name then First Name

Doe, John (ID #1)
Ho, Mike (ID #4)
Jones, Samantha (ID #8)
Pratt, Jacob (ID #12)
Public, Kendall (ID #2)