• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: **SOLVED** Or qualifier (including a many-to-many 'containsObject') give wrong results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: **SOLVED** Or qualifier (including a many-to-many 'containsObject') give wrong results


  • Subject: Re: **SOLVED** Or qualifier (including a many-to-many 'containsObject') give wrong results
  • From: Mark Gowdy <email@hidden>
  • Date: Sat, 19 May 2012 16:55:45 +0100

Thanks Chuck,
Half the battle with this stuff is knowing what road to choose.

When I constructed my query in the following way, it worked correctly.

EOQualifier q1 = Media.PRIMARY_CATEGORY.eq(cat).or(Media.SECONDARY_CATEGORY.eq(cat)); // result count = 16 (correct)
EOQualifier q2 = Media.OTHER_CATEGORIES.containsObject(cat); // result count = 11 (correct)
// Turn q2 into a subquery
ERXQualifierInSubquery q2AsSubQuery = new ERXQualifierInSubquery(q2);
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.
CLASS   : java.lang.IllegalStateException
MESSAGE : sqlStringForKeyValueQualifier: attempt to generate SQL for er.extensions.qualifiers.ERXKeyValueQualifier (otherCategories contains (com.aetopia.MediaCategory)'<com.aetopia.MediaCategory pk:"1118">') failed because attribute identified by key 'otherCategories' was not reachable from from entity 'MediaInfo'

But I think I can probably live with that for the minute.


Interestingly, the javadoc of 
ERXQualifierInSubquery 
mentions:
"This class can be used to work around the EOF bug where OR queries involving many-to-manies are incorrectly generated"


ERXQualifierInSubquery

----------------

Generates a subquery for the qualifier given in argument:


 EOQualifier q = EOQualifier.qualifierWithQualifierFormat("firstName = 'Max'", null);
 ERXQualifierInSubquery qq = new ERXQualifierInSubquery(q, "User", "group");
 EOFetchSpecification fs = new EOFetchSpecification("Group", qq, null);
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Or qualifier (including a many-to-many 'containsObject') give wrong results (From: Mark Gowdy <email@hidden>)
 >Re: Or qualifier (including a many-to-many 'containsObject') give wrong results (From: Mark Gowdy <email@hidden>)
 >Re: Or qualifier (including a many-to-many 'containsObject') give wrong results (From: Ramsey Gurley <email@hidden>)
 >Re: Or qualifier (including a many-to-many 'containsObject') give wrong results (From: Mark Gowdy <email@hidden>)

  • Prev by Date: Re: Or qualifier (including a many-to-many 'containsObject') give wrong results
  • Next by Date: Custom property returning NSDictionary with values appear nil in ERRest response
  • Previous by thread: Re: Or qualifier (including a many-to-many 'containsObject') give wrong results
  • Next by thread: Re: Or qualifier (including a many-to-many > 'containsObject') give wrong    results
  • Index(es):
    • Date
    • Thread