DataLab secondary queries
A secondary selection runs once for each Entity a primary selection finds, and its criteria can compare against that primary Entity. Eg: for each pump, the valves within 50 metres of it.
In Operator a saved query gets a secondary selection by choosing "Reference in a secondary selection" as its action. The pairs it finds can then be related, merged, counted, or used to copy values across.
This article will cover how a secondary selection references the primary one, how to search it, and the actions that use both. Selections and criteria are described in DataLab queries, and running actions in DataLab actions.
Referencing the primary Entity
A secondary selection has the same shape as a primary one. These criteria can read the primary Entity:
Set "LimitToPrimary" to true on the secondary selection to keep only secondary matches that the primary selection also finds. Eg: pairs of Entities from the same set.
Searching a secondary selection
Send both selections to "v3/datalab/runSearch". The secondary one is what runs. Without "PrimaryEntityIDs", "Skip" and "Load" page through the primary Entities, and the unique secondary matches are capped at "Load". With "PrimaryEntityIDs", only those primary Entities are used, and the result is capped at 10,000 with a warning.
The response's "Items" are the secondary Entities, and "Mapping" lists the secondary IDs found for each primary ID. Counting a secondary selection needs "PrimaryEntityIDs", and "IndexOf" is not available.
Run a secondary search
Action: Set attribute
With a secondary selection, "set-attribute" can copy values between the two sides. "ValueOption" PRIMARY reads the value from an attribute, so "Value" carries an "AttributePath" instead of a literal.
Action: Relate
Creates a relation of one Relation Type between each primary Entity and each of its secondary matches. You can read about relations in Entity relations.
Action: Delete relations
Deletes the relations of one Relation Type between each primary Entity and its secondary matches. Note the default direction differs from relating.
Action: Merge
Updates each primary Entity from its secondary matches by a Data Mapping, with each secondary Entity as the source and the primary Entity as the target. The secondary Entities are not deleted. You can read about the mapping in Data Mapping.
Action: Save secondary count
Writes the number of secondary matches onto each primary Entity.