Group constraint at design time

I want to implement group constraints at design time in my application. I have checked the user guide but not sure how I can implement the following constraint.

Here is the scenario.
I have a table of UserExt where the user is an Entity and this UserExt table has a Composition table (UserExtCompany) that contains the list of Companies with a checkmark that indicates if the user has access to that company.

What I want is, the user will have access to only those companies that are checked in the UserExtCompany entity.

In the example (codes) from the user guide, only shows hard-code constraints but in my case, I need something which is defined by a user about the access as described above.
Note that I am going to use this in a multitenant add-on environment.

Thanks for sharing any sample or cone-snippets.

Hi,

Based on your description, the JPQL constraint should look like below:

@JpqlConstraint(target = Company.class, 
    join = ", myproj_UserExtCompany uec, myproj_UserExt ue", 
   where = "{E}.id = uec.company.id and uec.checkmark = true and uec.user = ue and ue.id = :session$userId")

Note that such constraint adds two additional joins to any request to load Company from DB. If tables are large, it could lower performance.

Here are extracts from the doc page:

  • The join attribute value is added to the from query clause. It should begin with a comma, join or left join.

The following predefined constants can be used in JPQL parameters:

  • session$userId – ID of the current user (in case of substitution – ID of the substituted user).