Using foreign key properties and type key properties in row queries
Selecting a foreign key or type key property
as a column in a row query does not provide access to the properties
of the entity instance or type code. If you select a column that is a
foreign key to a record in another database table, the column provides
the identifier value of that record. The type of the foreign key column
is gw.pl.persistence.core.Key.
If you select a column that is a type key, the column provides the value
of the type code. The type of the type key column is the corresponding
typekey class. For example, the type of an address type typekey is typekey.AddressType.
The following Gosu code sets up a row
query that returns the columns AddressType
and CreateUser for all
Address entity instances
and prints the values for each row.
uses gw.api.database.Query
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths
var query = Query.make(Address)
var results = query.select({
// The Type column has a type of typekey.AddressType
QuerySelectColumns.pathWithAlias("Type", Paths.make(Address#AddressType)),
// The User column has a type of gw.pl.persistence.core.Key
QuerySelectColumns.pathWithAlias("CUser", Paths.make(Address#CreateUser))
})
for (row in results) {
// Access the type code value and the entity instance ID
print(row.getColumn("Type") + " " + row.getColumn("CUser"))
}
The output from this code looks like the following lines.
business null
business 3
...
home 9
...
See also
