Constrain the input of an association

0
Dear, I want to model the following situation. I want to assign a mentor to a student. I have made the object student and the object mentor. I have associated them with a many to many relation. A mentor has a capacity, denoted with an integer value. If a mentor is assigned to a student, the number of assigned students must also be noted. I have done this with a microflow. If a particular mentor is full, the mentor could be overbooked but only when all other available mentors hasn't any spare capacity. The overbooking of mentors must be balanced across the available doctors. So what I want to have is an attribute in the object student where I can choose a mentor. If all mentors have spare capacity, I would like to get a list of all these mentors, but if 1 is full, I will only get the other mentors to see in that list. If all mentors are overbooked I want to get the least overbooked mentor (but if that is more than 1 I want them all to chose by myself). So what I thought: * Make a microflow and retrieve list of all mentors from database. * Then I think I have something to do with the XPath, but nothing works there. I want to make a restriction on the imported mentors. What do I have to do? I have also difficulties with making the end note, cause the end isn't a change of an object or something else, but it is a list of doctors.
asked
4 answers
0

Use a microflow seems like the way to go.. don't use a microflow to calculate the number of students otherwise the value isn't stored in the db and can't be used using a retrieval. Create an attribute which is filled with a overbookpercentage (float/currency > number of students:capacity)

  1. Retrieve a list of available mentors Retrieve a list of mentors with sorting where the capacity > number of students

if list is empty goto step below otherwise return list

  1. Retrieve the mentor with the lowest overbookpercentage and retrieve a list with mentors with the same overbookpercentage and return that list.
answered
0

Thanks for the fast answer. But it isn't totally clear for me.

How to calculate the number of students then, if not to use the microflow? It is indeed true that when I use in the XPath that I want all doctors for where capacity > number of students he gives an error.

And what do you mean with 'sorting where the capacity > number of students?'

And what must be the end node? What I have done now is making an attribute in student that I call mentor. I chose for this attribute the microflow as stated above and so the end node will be a list of doctors. But I do not know whether this is right.

answered
0

When you commit a student entity, get the associated mentor, for the mentor retrieve the number of students associated and place that value in a integer attribute on the mentor and calculate the overbookpercentage. Make sure that after deleting a student you do the same. This way you will have a field in your database with the number of students and a overtime percentage for each mentor, which you can use with an xpath retrieval.

On the student form you can add the reference to the mentor and use a microflow to retrieve the list of mentor(s) as specified above. The microflow should return a list of objects (mentor objects), sorting needs to be done in the microflow because you're using a microflow.

When you change the existing mentor for a student it becomes tricky because the currently selected mentor may become unavailable. You could add the currently selected mentor to the list if not available.

answered
0

Thanks for the answer.

One thing we still couldn't manage. We know what to do in this case, constrainting an association. We know that by clicking 'add' in the menu patient we will only see the doctors which are available. So we need an XPath on the association which says that (capacity - total assigned students) > 0. We know how to constraint an association in mendix by the XPath in the reference set selector option menu. But as you said we couldn't use attributes (total assigned students) in here which are calculated by a microflow. So indeed we may not calculate the total assigned students by a microflow. But how to calculate it then? Because when I say that the value of the totalassignedstudents isn't computed by the microflow but by database, it is possible to change the object of this value by a microflow. But this change isn't automatically when you assign a new student to a mentor. You need a 'compute-button' for this case. But this isn't what we want, we want that in every case the number of students which is assigned to a mentor is automatically computed.

What to do?

answered