I have an Entity named Files with attributes file_name and shared_with, shared_with is a many to many association of an Entity named Department.
When a user shares a file, they add more than one Department to share_with attribute, thus a single shared file can have many Departments.
Let us say i have two users, user1 in Department1 and user2 in Department2, how can a achieve that when user1 logs in and opens the Files browser can only see files which include Department1 in shared_with attribute.
I tried to implement the above code in my project but i failed,
Here is how my project is
I have Entities Myfiles , SharedFiles, Employee, Department
Myfiles has file name and shared_with attributes, shared_with is a many-many association with Department. Department has name and user attribute, user is a one-many Association with Employee. Employee has user (Association of user) and department attribute, department is a many-one Association with Department.
SharedFiles, has file attribute which is a one-one Association with Myfiles.
left join {E}.shared_with sharedDeps
left join mypr$Employee empl
left join empl.user usr on usr.id = :session$userId
left join empl.department userDep
sharedDeps.id = userDep.id
But you really should just experiment for a while with your constraint.