QCubed Query Clauses

All QCubed Query method calls take in an optional set of QQ Clauses. QQ Clauses allow you alter the result set by performing the equivalents of most of your major SQL clauses, including JOIN, ORDER BY, GROUP BY and DISTINCT.

The following is the list of QQ Clause classes and what parameters they take:
  • QQ::OrderBy(array/list of QQNodes or QQConditions)
  • QQ::GroupBy(array/list of QQNodes)
  • QQ::Count(QQNode, string)
  • QQ::Minimum(QQNode, string)
  • QQ::Maximum(QQNode, string)
  • QQ::Average(QQNode, string)
  • QQ::Expand(QQNode)
  • QQ::ExpandAsArray(QQNode for an Association Table)
  • QQ::LimitInfo(integer[, integer = 0])
  • QQ::Distinct()
OrderBy and GroupBy follow the conventions of SQL ORDER BY and GROUP BY. It takes in a list of one or more QQ Column Nodes. This list could be a parameterized list and/or an array.

Specifically for OrderBy, to specify a QQ Node that you wish to order by in descending order, add a "false" after the QQ Node. So for example, QQ::OrderBy(QQN::Person()->LastName, false, QQN::Person()->FirstName) will do the SQL equivalent of "ORDER BY last_name DESC, first_name ASC".

Count, Minimum, Maximum and Average are aggregation-related clauses, and only work when GroupBy is specified. These methods take in an attribute name, which can then be restored using GetVirtualAttribute() on the object.

Expand and ExapandAsArray deals with Object Expansion / Early Binding. More on this can be seen in the Early Binding of Related Objects example.

LimitInfo will limit the result set. The first integer is the maximum number of rows you wish to limit the query to. The optional second integer is the offset (if any).

And finally, Distinct will cause the query to be called with SELECT DISTINCT.

All clauses must be wrapped around a single QQ::Clause() call, which takes in any number of clause classes for your query.

Select all People, Ordered by Last Name then First Name

Note now QQ::OrderBy gets two parameters here

Ben 5665564
kavita 2 arulyfred
Linda Brady
Brett Carlisle j
Mike Ho
sdhgfhsdg jai
good job
Nice Job
Samantha Jones
Jacob Pratt
Kendall2 Publics
sdf sdf
Alex Smith
Wendy Smith
Jennifer Smithfgfg
test test
moi tpo77
billy wilder
Karen Wolfe

Select all People, Ordered by Last Name then First Name, Limited to the first 4 results

Combining QQ::OrderBy and QQ::LimitInfo

Ben 5665564
kavita 2 arulyfred
Linda Brady
Brett Carlisle j

Select all People, those with last name Smith first, then ordered by First Name

Using a QQ::Condition as an ORDER BY clause

Alex Smith
Wendy Smith
Ben 5665564
billy wilder
Brett Carlisle j
good job
Jacob Pratt
Jennifer Smithfgfg
Karen Wolfe
kavita 2 arulyfred
Kendall2 Publics
Linda Brady
Mike Ho
moi tpo77
Nice Job
Samantha Jones
sdf sdf
sdhgfhsdg jai
test test

Select all Projects and the Count of Team Members (if applicable)

GROUP BY in action

ACME Website Redesign (5 team members)
Blah (6 team members)
Blueman Industrial Site Architecture (5 team members)
ACME Payment System (7 team members)