What is the logic behind the two retrieve activities in this microflow?

0
Hi everybody! Currently I am working with the training module to become a junior Mendix developer. In module 8.26, a microflow is created to display the current number of registrations. I have trouble getting my head around a couple of things: - Why is the first retrieve object by association? Couldn't it have been from datebase? - What is the link with the second retrieve object? I hope someone is able to explain the logic behind the microflow to me in a simple manner. Thank you in advance! Bart van den Heuvel
asked
2 answers
0

To me it looks like the first Retrieve action is retrieving the ScheduledCourse object which the input parameter of the microflow (Registration object) is associated to. Retrieve by Association first checks to see if the associated object is in memory already, and if not, it retrieves it from the database.

Then, it is retrieving all Registration objects which are associated to that ScheduledCourse object.

Then it counts the Registration objects to see how many total Registrations there are

Then it updates the ScheduledCourse object with this count, and commits it and refreshes in the client.

 

Does that make sense?

answered
2

The reason of retrieving it by association is the following:

By association is the preferred way, unless you need explicitly the database value or constraint is not an association or more complex. Because retrieve by association is a in memory retrieve if the data is available. If not it will result in a database retrieve. A in memory retrieve is quicker and thus the preferred way. 

In this particulair scenario, this microflow runs after commit of the Registration object. Save to say that database & memory are equal on moment of execution. So there is no offset between a retrieve by association and from database. By association is in that case quicker.

answered