Get list of all Managers (Parent entities) / Recursion

2
So I am in the process of refactoring stuff for my domain model. Originally, I had a Manager (1) ← (*) Employee, relationship, but realized that since managers have managers, I should probably just have an Employee_Employee association and build off of that. Here is what my domain model looks like now But in my app I would like a list of all employees who are managers. I am trying to think of an XPath or even a microflow that asks “Is this employee a manager”?    I am also needing to use this in a recursive microflow that gets all descendent employees under a manager. What I currently have starts with the first list of child employees under the parent (xpath is [Module.Employee_ManagerEmp = $IteratorEmployee]. I’d use a similar Xpath here as for the overview page to determine if they are a manager or not. But if there is a better way to do this recursion let me know, it’s my first time attempting it in Mendix. Thanks in advanced, and as always let me know if there any questions.   Shaun
asked
2 answers
3

Hi Shaun,

In Mendix, you can see if an association is populated with the following Xpath:

Employee_ManagerEmp/Employee

This will evaluate to true if an association is populated, so in your case if an employee has a manager assigned.  To get a list of Employees who are managers, I think you’ll need to use the reversed keyword, like this:

Employee_ManagerEmp[reversed()]/Employee

this will return true if an employee is a manager of one or more employees.

 

In my experience, its always helpful to test this with test data where you know what the answer is to ensure that you are getting the results you want.

Hope this helps,

Mike


I created the following example:

And a page with 2 grids.  The first shows all employees, the second shows only those employees who are managers:

The Xpath for the second grid is:

[MyFirstModule.Employee_Manager[reversed()]/MyFirstModule.Employee]

 

answered
0

1-* recursion seems logic at first hand, but is not. Answer this: what happens if an employee who is a manager leaves the company? And (temporarily) not replaced. To the employee a manager is always someone playing the role of Department manager, Career-advisor, buddy, HR-councelor and each has different tasks. An extra entity may be something to consider.

Back to your question, “an XPath or even a microflow that asks “Is this employee a manager”: an employer is (also) a manager if the object’s association is not empty.

answered