Logical operations on entity selections

Automatically translated from English

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.

Logical operators on entity selections example

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.

Example

An example is worth a thousand words! Let’s take a look at employees and their food preferences.

CLASSIC 4D:

//A named selection "meat" is created before
// ...
QUERY BY ATTRIBUTE([Employee];[Employee]food;"fish";=;True)
CREATE SET([Employee];"fish")
USE NAMED SELECTION("meat")
CREATE SET([Employee];"meat")
UNION("fish";"meat";"result")
USE SET("result")
CLEAR SET("meat")
CLEAR SET("fish")
CLEAR SET("result")

ORDA:

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.

C_OBJECT($eatingFish;$1;$eatingMeat;$result)
 
$eatingMeat:=$1
//Get employees eating fish
$eatingFish:=ds.Employee.query("food.fish=:1";True)
//Get the union of the 2 entity selections $eatingMeat and $eatingFish
$result:=$eatingMeat.or($eatingFish)
$0:=$result

 

• Product Owner •

Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.