Conditional visibility based on association

Hi, I am trying to set conditional visibility based on an expression. I have object X and object Y, which are associated to one another by a many-to-many relationship. I want to either hide or show object X by checking whether it is associated to object Y (I have both objects in context). However, as the relationship is based on a many-to-many relationship, writing a basic equals expression results in an error as it cannot compare an object to a list.  For now, we are retrieving the associated object in another context. Yet, this is not desired as it might lead to negatively impacting the performance of the application as we call this logic approximately 50 times on load of a certain page.  Is there a way to check whether an object exists in an association when writing a conditional visibility statement for a many-to-many relationship?   Thanks in advance! 
1 answers

I might misunderstand the question but if I understand correctly you have a dataview of object X and either want to show the associated objects Y if there are any or do not show the association if none is there?

Because that you can achieve to set this expression on the conditional visibility  of the reference selector:

if $currentObject/MyFirstModule.X_Y = empty then false else true

Or am I missing the point here?