Check if there is any link in a many-to-many-relationship

Hi all,
I am modelling with 2024.06-ext5 and I have the following constellation:
There is a broker model, a contract model and a many-to-many-relationship between them.
Now I want to check in the brokerCDM if there is any linked contract for the broker.
For to-many-relationships I would do it with “t_docRef”, but for many-to-many-relationships, this does not seem to work.

Hey @clara-fleet-yew,
t_docRef should work for all kinds of relationships (to-1 and to-many) alike.
But keep in mind, that this only works on client side. So it is only recommended for UI control.
You could use a construct like GroupFilled or AtLeastOneGroupFilled to check if any Relationship exists. Or check on a Required Field. This would work both on Client and Server Side.

The t_docRef looks only into one direction, but you make a difference between “to-many” and “many-to-many”. Why so?

Hi @felix-blazing-river,
it does not matter if I use AtLeastOneGroupFilled(relationship*/t_docRef) or AtLeastOneFieldFilled(reltationship*/mandatoryField), the validation does not work at all…
In addition, the FieldFilled(t_docRef) in the to-many-relationship does also not work in this project.

It was neccessary to make the t_docRef Fields global. Now it works :slight_smile:

Hi @clara-fleet-yew

You raised my interest when you wrote:

As a quick follow-up question, how is this validation that you are expecting triggered and what sort of validation are you expecting?

  • Button with full validation
  • Button with partial validation
  • Interacting with the Binding and then cliking away

The trigger is a confirm. It is about a broker, when I deactivate it (confirm = null), then there should be a warning in case that I have linked contracts to that broker. But I can still proceed. The warning is directly shown, when I deactivate the broker by changing the confirm to null. This is why I need the global property.

Thanks for the clarification. This makes perfect sense now.

You need the rule to be triggered when the user changes the value of the Confirm Field.

As the Rule is something like

FieldNotFilled(MyConfirmTrigger) And AtLeastOneFieldFilled(relationship*/t_docRef)

you need to ensure that all of the Fields involved with the rule are “relevant”. MyConfirmField is relevant as the user is changing its value. You make the t_docRef Field relevant in this moment by setting the “Global” flag. This means that this Field is always relevant.

You can find more information on Relevant Fields in the documentation.