Ordering query results on related instance properties
The ordering methods of the query builder APIs let you order results on the properties of related entities. To do so, specify an object access path from the primary entity of the query. The access path can traverse only database-backed foreign keys, and must end with a simple, database-backed property. The access path cannot include virtual properties, methods, or calculations. You do not need to join the related entities to your query to reference them in the parameters that you pass to the ordering methods.
The following Gosu code orders notes, based on the date that the activity related to a note was last viewed.
uses gw.api.database.Query
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths
var queryNotes = Query.make(Note) // Query for notes.
var resultNotes = queryNotes.select()
// Sort the notes by related date on activity.
resultNotes.orderBy(QuerySelectColumns.path(Paths.make(Note#Activity, Activity#LastViewedDate)))
