I have the following data structure:
-> users: List<User>
-> emailAddresses: List<EmailAddress>
-> email: String
Now I want to detect, if an email address is already included in a client if I add a new user to the client (e.g. client contains user 1 and user 2, user 1 contains email "te...@test.de
", user 2 contains "te...@test.de
", if I want to add user 3 containing also email "te...@test.de
" I want to reject in my code).
So far I realized my query this way (#18:2 is a client, #12:1 is the new user to add, I just expand all existing email addresses from the client and want to get the union to all new users email addresses):
SELECT expand($c) LET $a = (SELECT expand(emailAddresses) FROM (SELECT expand(users) FROM #18:2)), $b = (SELECT expand(emailAddresses) FROM #12:1), $c = unionall($a, $b)
What I need is distinct($a, $b) or intersect, but both doesn´t work (at least in OrientDB 2.1.2) -> distinct() only allows for 1 field, intersect() throws:
java.lang.ClassCastException: com.orientechnologies.orient.core.sql.query.OResultSet cannot be cast to com.orientechnologies.common.util.OSupportsContains
So my question is: Is there an easier way to achieve such a check (also regarding performance of the query, because there might be a lot of users with email addresses per client) or do I face a bug of OrientDB or are there any other possible ways?
Thanks for you help!