Forum Discussion
Dynamic RLS with multiple tables
- 3 years ago
Actually, I had some time now. Here is original post, tweaked for User : UserAllowedCompany to have M:M relationship.
The filter from User will propogate as long as it travels through a single direction filter. So, either one --> many relationships from the one side OR single filter direction many --> many relationship from the left (A) side of A filters B.
As you've noted, it doesn't work nicely when traveling from the other direction, many --> one, like UserAllowedCompany (many) --> (one) Company.
To get this working without relying on bidirection filtering, you'll need to define an RLS filter rule on Company. Note that once that is working, it looks like the RLS filter will propogate throughout the rest of your model by leveraging the filter directions on (the rest showing are one --> many relationships).
Something like the following should work as the filter on Company:
CALCULATE( NOT ISEMPTY( UserAllowedCompany ), User[Id] = USERPRINCIPALNAME() )
Note that, even though you should also have the User[Id] = USERPRINCIPALNAME() filter on User, the RLS filters aren't evaluated in order, so you need to re-incorporate the underlying USERPRINCIPALNAME() filter any time you are defining a new RLS filter.
Here are some screenshots with a dummy model similar to yours in case helpful.