• 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: EOAndQualifier on child entity property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOAndQualifier on child entity property


  • Subject: Re: EOAndQualifier on child entity property
  • From: Timo Hoepfner <email@hidden>
  • Date: Tue, 22 Aug 2006 19:39:16 +0200

I don't see what I can do with a IN() statement, because I know there ar lot of objects having ANY tags the user requested, but I want to get all objects having ALL tags the user requested :-/
I'd use ERXInQualifier in Project Wonder to get something like:

WHERE tag1 IN ('tag1', 'tag2')


Maybe this one can help (didn't try):

Wonder's ERXToManyQualifier:

/**
* Optimized toMany qualifier, much, much better SQL than the Apple provided qualifier.
* Really nice when you want to find all the eos that have say five of the
* ten eos in their toMany relationship. This qualifier will always only
* generate three joins no matter how many eos you are trying to find. Example usage:
* <pre><code>
* NSArray employees; // given, can be null
* // Find all of the departments that have all of those employees
* ERXToManyQualifier q = new ERXToManyQualifier("toEmployees", employees);
* EOFetchSpecification fs = new EOFetchSpecification("Department", q, null);
* NSArray departments = ec.objectsWithFetchSpecification(fs);
* </code></pre>
* If you want to find say departments that have 5 or more of the given
* employees (imagine you have a list of 10 or so), then you could
* construct the qualifier like: <br>
* <code> ERXToManyQualifier q = new ERXToManyQualifier ("toEmployees", employees, 5);</code><br>
* or to find any department that has at least one of the given employees<br>
* <code> ERXToManyQualifier q = new ERXToManyQualifier ("toEmployees", employees, 1);</code>
*/


I think Pierre's QualifierAdditions were already mentioned, especially these ones could help:

ExistsInRelationshipQualifier

/**
* <p>Qualifier to check for the presence of objects matching a given qualifier in a to-many relationship.</p>
*
* <p>An object matches the qualifier if the to-many relationship identified by at keyPath contains at least one
* object matching the nested qualifier as passed to the constructor.</p>
*
* <p>This qualifier actually os of most interest when nested within an EONotQalifier. This allows for verifying
* that a relationship does not contain any object matching a given qualifier.</p>
*
* <p>While in-memory qualification is supported, its use is not adviseable over performance concers.</p>
*
...
* @author Pierre Bernard http://homepage.mac.com/i_love_my/ webobjects.html
*/


InSubqueryQualifier

/**
* <p>Qualifier to match objects according to the result of a nested query.</p>
*
* <p>An object matches the qualifier if the value at keyPath is included in or intersects with the result of
* the subquery. If the keyPath leads to a relationship the entity and attributes to fetch by the subquery
* are implied. Else they must be specified to the constructor.</p>
*
* <p>While in-memory qualification is supported, its use is not adviseable over performance concerns.</p>
*
...
* @author Pierre Bernard http://homepage.mac.com/i_love_my/ webobjects.html
*/


As final resort, you can go back to use raw SQL (I was using that in conjunction with vertical inheritance, where none of the qualifiers were working correctly. Not very efficient, but it works...):

private static final String SQL_COLUMN_NAMES = "id, name, bla, blubb, etc"; // order is important

public static NSArray withKeyword(EOEditingContext ec, Keyword k, String name, boolean recursive) {
if(k==null) {
return NSArray.EmptyArray;
}


String fromClause="FROM assets t0, assets_keywords t1 ";
String whereClause;
if(recursive) {
// using ERXGenericRecord.primaryKey() here
NSArray keywordIDs=(NSArray) k.withChildren().valueForKey ("primaryKey");
String kIDs = keywordIDs.componentsJoinedByString(",");
whereClause="WHERE t1.keyword_id IN ( "+kIDs+" ) AND t0.id = T1.asset_id";
} else {
whereClause="WHERE t1.keyword_id="+k.primaryKey()+" AND t0.id = T1.asset_id";
}
if(name!=null) {
whereClause += " AND name LIKE '%"+name+"%'";
}
return findBySql(ec, recursive ? true : false, fromClause, whereClause);
}


private static NSArray findBySql(EOEditingContext ec, boolean distinct, String fromClause, String whereClause) {
String sql="SELECT ";
if(distinct) {
sql+="DISTINCT ";
}
sql+=SQL_COLUMN_NAMES+fromClause+whereClause;
EOFetchSpecification fetchSpecification=new EOFetchSpecification(Asset.ENTITY_NAME,null,null);
fetchSpecification.setHints(new NSDictionary (sql,EODatabaseContext.CustomQueryExpressionHintKey));
return ec.objectsWithFetchSpecification(fetchSpecification);
}


Timo

_______________________________________________
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: 
 >EOAndQualifier on child entity property (From: Yann Bizeul <email@hidden>)
 >Re: EOAndQualifier on child entity property (From: Sacha Michel Mallais <email@hidden>)
 >Re: EOAndQualifier on child entity property (From: Chuck Hill <email@hidden>)
 >Re: Re: EOAndQualifier on child entity property (From: "John Huss" <email@hidden>)
 >Re: EOAndQualifier on child entity property (From: Yann Bizeul <email@hidden>)

  • Prev by Date: Getting the component causing an error
  • Next by Date: EOGenerator and takeStoredValueForKey dumb question
  • Previous by thread: Re: EOAndQualifier on child entity property
  • Next by thread: Re: EOAndQualifier on child entity property
  • Index(es):
    • Date
    • Thread