4D Blog

Home Tips ORDA – Genealogy – Episode one

ORDA – Genealogy – Episode one

August 3, 2018

Tips

We can all agree that ORDA is a great 4D V17 feature. A kind of revolution in the way of thinking and programming. 4D databases will never be seen the same way as before.

ORDA allows you to conceive advanced applications in less time, with more readable and clean code. To show you the power of ORDA we’ve prepared a series of tips for you, divided into three episodes. In this first episode, we’ll demonstrate how links should now be considered more as entities and entity collections, and we’ll show you how listboxes can now be based on entity selections, rather than selections or arrays.

Download Genealogy – Episode one

Using recursive relationships

In order to demonstrate the power of 4D and ORDA, we’ll use a highly recursive database using a single table named PEOPLE.

This table contains five main fields: Lastname, Firstname, Birthday, Gender and ID (which is obviously unique).
Then come three more fields: FatherID, MotherID and PartnerID that connects each person to three other people if they exist (Partner) or if they are known (Mother and Father).

relationship definition

Now let’s focus on the relationship definition. In both directions (1 to N and N to 1), relationships can be named. Using ORDA, these names are going to become very significant and useful. In the many to one direction, the name is not only a string, it is an entity of the PEOPLE table, in the same way as the PEOPLE entity where the relationship originates. In the one to many direction it’s even more, the name represents an entity selection.

Without anticipating too much, you can guess that with the object notation, you’ll be able to use PEOPLE.Father, as well as PEOPLE.ChildrenAsFather, to reach either a single person (the father) or a group of persons (the children).

blank

A new kind of listbox

blank

Until now, the contents of list boxes (the data source) were either arrays or selections. From now on, the contents can also come from a collection or an entity selection. So let’s see how an entity selection can be used within a list box.

First of all, you have to create the entity selection using the new ds function. In this example, we’ll create a simple entity selection containing all of PEOPLE ordered by birthday, last name, and first name. This can be done in a single line, as shown below. That’s all you have to know for now about ds!

people:= ds.PEOPLE.all().orderBy("Birthday asc, Lastname asc, Firstname asc")

Once you get the people entity selection, just set it as a property of the list box and you’re – almost – done!

“THIS” is fantastic

As in regular list boxes, the contents of every column must be defined. In our case, as long as we use an entity selection, the contents of each column will be defined as an expression. To do this, we’ll use a new keyword  (“This“) which will refer to the the current item of the entity selection.

To display people names and birthdays, the expression can be as simple as:
This.Lastname
This.Firstname
This.Lastname + " " +This.Firstname
This.Birthday

Now comes the power and the fun: if you want to display the Lastname of the Father, the Birthday of the Mother, or the Firstname of the Partner, just use the entity names you gave in the relationship definitions (Father, Mother, Partner, etc.) and write:

This.Father.Lastname
This.Mother.Birthday
This.Parter.Firstname

Of course, you can go even further if you want to know the names of the four grandparents of the Partner of the current people by writing:

This.Partner.Father.Father.Lastname
This.Partner.Father.Mother.Lastname
This.Partner.Mother.Father.Lastname
This.Partner.Mother.Mother.Lastname

One last step (for today!): I also want to display the number of children and siblings this person has. Can I do that ?
Sure, that’s quite easy. For the children, just use the ChildrenAsFather entity selection defined in the relationship definition. As with every entity selection, it has a length property. Simply define the expression like this:
This.ChildrenAsFather.length + This.ChildrenAsMother.length   // one of them will equal zero, ChildrenAsFather.length for women and vice versa.

For the siblings  you’ll need to “go up” to the mother (or father) and “go down” to the children. So the expression would be : 
This.Mother.ChildrenAsMother.length - 1 // minus 1 to remove the current people from the number of his/her siblings :-)

blank

And here’s the result… without a single line of code !

blank

 

To be continued, stay tuned!

Discuss

Tags ORDA, Programming, v17

Latest related posts

  • September 15, 2025

    Find the right spot in your 4D Write Pro document with AI

  • September 2, 2025

    Intelligent 4D Write Pro document analysis with AI

  • August 25, 2025

    ORDA – Constructor and touched event – Detailed behaviour through a network

Roland Lannuzel
Roland Lannuzel
• Product Owner & 4D Expert • After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy