SOQL has a very rich dot notation to traverse relationship (lookup) fields in order to access other fields on related records within a single query. To obtain the following information in a tabular form, it needs to traverse up and down the relationships across many of the objects in the FormulaForce application object schema:
- The season name
- The race name
- The race position
- The driver's name
- The car name
First, let's consider the following SOQL and then look at how it and the data it returns can be encapsulated in a ContestantsSelector class method. Note that the common order by clause is also applied here, as was the case in the previous example:
select Race__r.Season__r.Name, Race__r.Name,RacePosition__c, ...