Non-Table Bound Attributes
Occasionally you may need to create custom database queries which retrieve other columns
or values which are not in the table itself. This may be a one-off column in another
table, a calculated value, etc.
You can utlize the generated data object to easily retrieve these virtual attributes
from the object, itself, as long as you code your custom database query correctly. In short,
if you prefix any additional or non-table bound columns with a double-underscore ("__"), the
generated object will read in the column as a virtual attribute. You can then use the generated
method to retrieve the value of the data.
In our example below, we create a custom SQL query which uses SQL's COUNT
subselects to calculate the number of team member for each project.
By utilizing Virtual Attributes
, complex queries with calculated values,
subselects, etc. can be retrieved in a single database query, and all the values can be
stored in the data object, itself.
List All the Projects and Its Team Member Count
ACME Website has 5 team members.
State College HR System has 7 team members.
The last security project has 4 team members.
ACME Payment s has 4 team members.