Property projection
Projection – Abstract
Purpose: Returns the value of a property of an entity from the context of the query.
A Property projection returns the value of a property of an entity, provided that access to the selected Property is technically representable.
The Property projection is the most important projection to get values for output columns, Restrictions and for grouping and sorting search results from the database.
In contrast to a Collection projection, a Property projection usually returns single values. If a Property is selected that affects the n-page in a (1:n) relation, the access via a Property projection generates (at least internally) one line for each value of the n-page.
Depending on the data type of the property specified in the type definition for the entity in question, a property value can be a simple value or a more or less complex data object.
►IMPORTANT◄ In order to conveniently access the fields of attributes of an entity, it is generally convenient to use one of the following specialized Projections:
Typed attribute projection for accessing typed attributes for a given (sub)type.
Attribute projection for access to non-typed attributes.
Both Projections offer a Property parameter that can be used to optionally access a specific field in the value of the attribute.
►NOTE◄ If the Property projection defines an output column (in a CSV or tuple search), the field value may be subject to some 'formatting'
Example:
A dynamic enumeration value is generally persisted in the database as a Long value (ordinal), while its internal 'name' (name) appears in a CSV output column, and a DynamicEnumValue object (with the name XML attribute) appears in a tuple search.
When a Property projection 'reads' the address Property in a search for Users or Company accounts, the output in a CSV search returns the string image of the address entity (e.g. 21052:de.lobster.scm.base.address.Address@1c6bbbc7), i.e. little 'user-friendly' information apart from the prefixed ID (here: 21052). In contrast, a tuple search returns the 'address' entity completely as a complex value, so that all details can be 'extracted' from the search result afterwards.
Configuration
Parameter |
Type |
Description |
Name |
String |
The optional Name parameter can be used to assign an (alias) name to the projection
|
Property |
String
|
From a purely technical point of view, the Property parameter is a String that must be interpretable in the context of the search as a path to a property of an entity type contained in the context of the query, otherwise an error will occur when the search is executed. In the user interface, a Combobox element with search function appears for the Property, which offers all possible paths to properties available in the context for selection via a dropdown. If available, localization texts are used in addition to the internal names that are decisive for the path. ►NOTE◄
|
Example
Simple example: Field restriction for a search
The Where condition of a search for any entity type should filter out those instances for the entity that have the same timestamp in the 'Last modified' (lastModified) property as in the 'Created' (created) property.
The search lists all entities of the selected type that have been saved exactly once so far – at 'creation' (see Common action event) and whose data status has not changed since then.
Configuration:
The screenshot shows the configuration for the Where condition in a search:
The Name is irrelevant here, as it will not appear in the search result. ►NOTE◄ As can be seen in the screenshot, the property name appears with an asterisk (*) in both cases. These are therefore indexed properties. |
|
►IMPORTANT◄ When configuring the Field restriction, note that the context menu for the check value (left) offers only Projections for selection. For the compare value, on the other hand, either Projections or Resolvers (for constant values) can be used. The Projections appear in the context menu for the compare value (right) in a separate 'Search' category.
Simple example: Output columns' for properties in a tuple or CSV search
In the context of a tuple or CSV search, all 'output columns' must be explicitly defined by Projections.
In the result of a search for Users, the 'Username' (username) and the assigned role(s) should appear.
Configuration:
In the context of a CSV search for the 'User' (see Users) entity type, we define two output columns:
►NOTE◄ As the following runtime example shows, the label 'ROLES' would be misleading. |
|
Runtime example:
As the query result (right) shows, multiple lines appear for the same USER if it has more than one role to choose from. The Property projection on the 'multi-value' roles property leads to the multiplication of the user data (here: USER) per role. The ROLE column always outputs exactly one ID of a role. |
USER,ROLE |
►NOTE◄ To output multiple roles within the same USER line, one could use a Collection projection.
More complex example: Obtain 'role name' instead of ID via JOIN
Based on the previous example, the role should no longer be identified by ID but by role name (roleName).
Since only the Long reference is included in the user account, we need to explicitly add each referenced role entity to the context of the CSV search to access the role name.
We can do this, for example, using a Entity join.
Configuration:
To the CSV search from the previous example, we add a Entity join that is parameterized as shown on the right:
►NOTE◄ Since the On condition refers to a 'multi-value' field of the entity, the condition is checked against all single values listed in the 'Roles' property. The join assigns the referenced role (r) to each roles entry. |
|
|
Once the Entity join is configured, the range for paths expands in the context of our Projections:
|
|
Laufzeitbeispiel: USER,ROLE |
We now use the existing Projection as a basis for ordering the results list A Property projection for a projection can be copied to the clipboard via the context menu (see menu symbol at the top left within the Property projection) and then pasted in the context of the Order by via the context menu as a projection added using the As you can see in the screenshot, our sorting should be done first by role name and then by user name. ►NOTE◄ A reference to an already defined 'output column' via the column alias (here: ROLE, USER) cannot be established based on the Order by (and also Group by). The same projection must therefore be created multiple times if required (as in our example). The Name used is irrelevant, but was 'taken along' here when copying. |
|
Laufzeitbeispiel: USER,ROLE |