Contents of result sets from entity queries

Result objects from entity queries contain a list of references to instances of the primary entity type for the query. For example, you write the following Gosu code to begin a new query.

var query = Query.make(Company)

The preceding sample code sets the primary entity type for the query to Company. Regardless of related entity types that you join to the primary entity type, the result contains only instances of the primary entity type, Company.

To set up the preceding query as an entity query, call the select method without parameters, as the following Gosu code shows.

var entityResult = query.select()  // The select method with no arguments sets up an entity query.

The members of results from entity queries are instances of the type from which you make queries. In this example, the members of entityResult are instances of Company. After you retrieve members from the results of entity queries, use object path notation to access objects, methods, and properties from anywhere in the object graph of the retrieved member.

The following Gosu code prints the name and the city of the primary address for each Company in the result. The Name property is on a Company instance, while the City property is on an Address instance.

for (company in entityResult) {  // Members of a result from entity query are entity instances.
  print (company.Name + ", " + company.PrimaryAddress.City)
}