How to choose from a list within another list

0
Dear all,  I am quite new to Mendix, so please excuse me if this a stupid question. I have been stuck with a problem for quite some days now and I searched the forum for ideas but can still not seem to fix it. The closest to what I am trying to achieve, I could find in this post: https://community.mendix.com/link/questions/15722 To explain my situation a little bit better. I have an app where a user has an account (entity). Within this account the person can add contactpersons (entity). The next step is that a person (an account) can add an event where they were together with these contactpersons. What I am trying to achieve is that this account can add the contactpersons to an event. This means that the account would have to choose from a list of contactpersons and that these will be added to the event. The thing is that they can add multiple events with the same contactpersons so I can not save an event in a contactperson. I made an extra entity(connection) to try and save all of these entities, but then I don't know how to properly save the data that it will show 1 event with multiple contactpersons.  For now I have the following associations: Account 1 – * Contactperson Account 1 – * Event Account 1 – * Connection Contactperson 1 – * Connection Event 1 – * Connection The solution is probably super easy but once you stuck in a web of thoughts and multiple tries and failures, it's really hard to look at it with a different point of view. I hope someone can help me out and thanks in advance!   Leonie
asked
2 answers
0

You need multiple – multiple associations. Because a contactperson can have multiple events where the person is attending and an event has multiple contactpersons. But if I where you I would change the names a bit because that makes it less confusing I think. Let's say we have Events. Events have a host and attendents. The host is the one who can add attendants to an event. Now all attendants and host all are an Person object and all Persons have an account.

So it would look like this:

The multiple – multiple reference refer to each other so that when you have an event you could retrieve all the attendants and for each Person you can retrieve all the events. So when a person creates an event he becomes the host of that event. Each event can only have one host. This way you can achieve that only hosts can add attendants for their own events. Does this helps a bit?
Regards,

Ronald

 

 

answered
0

To achieve this create the following domain model:

Make sure the association between Event and ContactPerson is *:* and the association is set to let both entities refer to each other (double click the association to change this option).

On the account page create a datagrid to add new contact persons(via association), make sure to delete the reference selector for the account on the NewEdit page of the ContactPerson (this is automatically added when generating the page).

Now you can add as many contacts to an account as needed.

Also create a datagrid for the Events in the same way as for the contacts.

On the Event_NewEdit page remove the reference selector for the account (if generated) and add a reference set selector widget where you select the ContactPerson entity over the many to many association:

Generate the select page by right clicking the add button and now for the part to restrict the selection of the Contactpersons to those that are associated with the Account. In the properties of the reference set selector there is an option called constraint by:

Press the Edit button and select the option available:

Now the selectable contacts in the select page are constraint by the selected path over the account entity. The constraint needs to be set on the reference set selector and not the select page itself! 

The same result can be achieved by using the xpath option in the selectable object properties.

Hope this helps you to achieve the desired result

answered