Function: FIELDS
Query fields in Wonderful Relations are equivalent to columns in an SQL SELECT statement. If no fields are explicitly defined, the query defaults to SELECT * FROM TABLE
, retrieving all available columns.
Parameters
Title
Defines the display name of the field (used in lists but does not affect SQL execution).
Database Table
Specifies the table or view where the data is fetched from. This could be a standard table, a view, or even DUAL
for special cases.
Column Name
Used when no SQL Function is provided. The combination of table and column name represents the selected field in the query.
SQL Function
Allows the use of custom SQL expressions.
- Example: Aggregations such as
SUM(hours) AS total_hours
- Important: If the query is used as a DataTable query, renaming fields (
xyz AS field
) should be handled carefully to maintain compatibility.
Is Key?
Defines whether the field is a primary key.
- It should be unique per row.
- Typically, an ID column is used as the key.
- Essential for linking and joining related data.
Visual Examples
Example: Aggregated Field (Summed Hours)
The following query field sums up the total hours for a project and rounds the result:
Results in:
ROUND(sum(wp_your_project_table.hours),2) as `total_hours`
Example: Standard Column (Title Field)
A simple query field referencing the title
column from wp_wr_entity
:
Results in:
wp_wr_entity.title
Summary
✅ Equivalent to SQL SELECT columns
✅ Supports aggregations and SQL functions
✅ Allows custom naming and transformations
✅ Essential for linking and joining data
Query Fields provide a structured and flexible way to define which data is retrieved and how it is processed in Wonderful Relations.