ERXOrQualifier finalQuery =
new ERXOrQualifier(
new NSArray( new EOQualifier[] {q1, q2AsSubQuery
} ));
// result count = 27 (CORRECT !!)
The SQL it generates is:
SELECT DISTINCT t0.MEDIA_PK, t0.PRIMARY_CAT_FK, t0.SECONDARY_CAT_FK
FROM mb_media t0
WHERE (t0.MEDIA_PK IN ( SELECT t0.MEDIA_PK FROM mb_media t0, mb_cat_media_join T1, mb_categories T2 WHERE T2.CAT_PK = ? AND t0.MEDIA_PK = T1.MEDIA_CK AND T1.CAT_CK = T2.CAT_PK ) OR (t0.SECONDARY_CAT_FK = ? OR t0.PRIMARY_CAT_FK = ?))
The only problem now is, that fetchSpec.setPrefetchingRelationshipKeyPaths(new NSArray<String>(Media.TO_ONE_INFO)); no longer works.