The ORDA series continues! In this blog post we’ll see how to use logical operators on entity selections!
These operations allow you to get intersections, unions, or differences between two entity selections like you can with classic 4D sets.
In classic 4D, you use sets to perform logical operations on several query results. You must create a set after each query, perform the logical operation on the sets, and finally update the current selection of the concerned table with the result set. It’s a bit heavy! Thankfully, with ORDA things are becoming much lighter! Each query gives you an entity selection to which logical operators can be directly applied!
ORDA provides the following methods to perform logical operations on two entity selections:
– and(): get the intersection between two entity selections (entities belonging to both)
– or(): get the union between two entity selections (entities belonging to one or to the other)
– minus(): get the difference between two entity selections (entities belonging to one and not to the other)
These methods can also be applied to an entity selection and an individual entity.
An example is worth a thousand words! Let’s take a look at employees and their food preferences.
//A named selection "meat" is created before
QUERY BY ATTRIBUTE([Employee];[Employee]food;"fish";=;True)
USE NAMED SELECTION("meat")
Here, we have a method which receives an entity selection as parameter. We return the union of the $eatingMeat entity selection and the $eatingFish entity selection.
//Get employees eating fish
//Get the union of the 2 entity selections $eatingMeat and $eatingFish