Suppose we have an employee table. An employee reports to a certain manager. Every manager is also an employee. This is an example of recursive database tables. What is the best practice in Outsystems when you have recursive entities? Are both solutions equal?
or
Hi Danny,
The best option for your problem is the first option, one entity with a column to the same table.
The option 2 works, but typically is used when an employee reports to more than one person, for example.
Thank you.
Thanks Gonçalo for your reply. I take this with me.
Hi Danni,
If you don't have other questions, please mark the post as solved.
Thank you
For your case, the first option seems to be the best. The second option can be used when an employee reports to more than one person (as Gonçalo stated) or when there are specific attributes for the reporting process.
Cheers,
António Pereira
I agree with both that for this simple example, the main difference is that the top solution only allows employees to report to one manager, and that you can't add attributes to the relationship.
In realistic applications, I would think that you would quickly find the first overly simplistic as
Dorine
Hi @Dorine Boudry
May I ask how to construct a recursive function to get all layer employee report to with the input as Employee ID?
not exactly sure what you are asking, i think you mean server logic, not function ? And what do you mean with 'recursive function' ?
Is your requirement to get the entire reporting tree from a single manager's id, or the other way around, the entire management tree starting from a managed employee id ?
And what are you going to do with it ? If you want to display in tree form on the ui, then you could use tree widget, and in that case, the widget itself will construct the tree from the raw data.
Sorry not being clear in my question. The question is about a server action to get entire reporting tree from a single manager's Id. The result of this will be then the input of ztree widget.
I though this server action is going to be a recursive function (which will call itself), but I still don't know how to do it.
I would let the dbms do the job, using recursive CTE, and as a result a list of employees, each with an id and parent id, in no particular order. The ZTree widget can deal with that and use the parentid's in there to make the correct tree.
So have a data action with an SQL widget, not an aggregate.
SQL will be something like
I realise I didn't answer you other question : "how do you build a recursive server action ?"
That is a matter of just calling the action inside it's own logic, so is easy to do. You just have to make sure you don't create an endless running logic, so you need to build in your logic a moment when recursion ends.
Thank you very much for your advice, the script works like a charm as always.
For the first option, is it true that the "ReportTo" attribute is of type "List of Employee Identifier"?
@Danny Eeraerts For the first option, is it true that the "ReportTo" attribute is of type "List of Employee Identifier"?