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

, 51 (ID #13)
2, 1 (ID #25)
2, 1 (ID #26)
asdads, 4 (ID #40)
asdads, 4 (ID #39)
asdads, 4 (ID #38)
asdads, 4 (ID #37)
asdads, 4 (ID #36)
asdads, asdas (ID #44)
asdads, asdas (ID #45)
asdads, asdas (ID #41)
asdads, asdas (ID #42)
asdads, asdas (ID #43)
asdf, asdf (ID #27)
ññ, 51 (ID #21)
ññ, 51 (ID #22)
ññ, 51 (ID #23)
ññ, 51 (ID #24)
ññ, 51 (ID #20)
ññ, 51 (ID #19)
ññ, 51 (ID #18)
ññ, 51 (ID #17)
ññ, 51 (ID #16)
ññ, 51 (ID #15)
ññ, 51 (ID #14)
Brady, Linda (ID #9)
Carlisle, Brett (ID #11)
Doe, John (ID #1)
Ho, Mike (ID #4)
Jones, Samantha (ID #8)
k, lol (ID #34)
k, lol (ID #33)
k, lol (ID #32)
k, lol (ID #28)
k, lol (ID #35)
k, lol (ID #29)
k, lol (ID #30)
k, lol (ID #31)
Pratt, Jacob (ID #12)
Public afd, Kendall (ID #2)
Robinson, Ben (ID #3)
Smith, Alex1 (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

2, 1 (ID #25)
asdads, 4 (ID #39)
asdads, 4 (ID #36)
asdads, 4 (ID #37)
asdads, 4 (ID #38)