Conflict in MANY_TO_MANY realtionship edit of common Entities in MultiTenant case

Hello folks,
My case is simple, I have different Companies (implemented as Access Groups) that manage a number of Shop Entities (Esercizi) and a common set of Suppliers (Fornitori).
To separate data between Companies, I used the https://www.cuba-platform.com/discuss/t/implement-multitenancy-through-access-groups multitenancy exemple, but I left the Suppliers Entity common.
Suppose I have Supplier S for both Company A and Company B. The thing is, now Company A not only can see the related Shops (Esercizi) of Company B under the same Supplier - which is normal - but can also remove that relationship which is bad.
Is there any workaround for this? Like adding a listener to the Suppliers Entity?
Thanks
Lucio

Hi Lucio,

You can employ constraints checked in memory to filter out unwanted elements of nested collections. It allows you to show only Shops available for the Company even inside common Suppliers.

Thank you!

I had the following where clause:


{E}.companySession = :session$companySessionId

That translated into Groovy script is:


{E}.companySession == userSession.getAttribute('companySessionId')

It worked a treat!