Re: EOAndQualifier on child entity property
Re: EOAndQualifier on child entity property
- Subject: Re: EOAndQualifier on child entity property
- From: Art Isbell <email@hidden>
- Date: Fri, 18 Aug 2006 11:15:07 -1000
On Aug 18, 2006, at 9:29 AM, Yann Bizeul wrote:
public Main doFind()
{
Main nextPage = (Main)pageWithName("Main");
NSArray tags = NSArray.componentsSeparatedByString(tag," ");
NSMutableArray tagsQualifiers = new NSMutableArray();
int i;
for (i=0;i<tags.count();i++)
{
EOQualifier q = EOQualifier.qualifierWithQualifierFormat("tag = %
@",new NSArray(tags.objectAtIndex(i)));
tagsQualifiers.addObject(new ExistsInRelationshipQualifier
("tags",q));
}
EOAndQualifier tagsQualifier = new EOAndQualifier(tagsQualifiers);
EOFetchSpecification f = new EOFetchSpecification
("Location",tagsQualifier,null);
nextPage.searchResults = session().defaultEditingContext
().objectsWithFetchSpecification(f);
return nextPage;
}
This makes me wonder whether you have modeled the Location <<->> Tag
relationship correctly. Using EOModeler's join in many-to-many
relationship functionality, you should end up with:
Location <->> LocationTag <<-> Tag
EOModeler will flatten the Location.locationTags and LocationTag.tag
relationships into Location.tags.
Assuming that the tag value is in the Tag.tag attribute, then you'd
want all Locations whose tags.tag array contains both "tag1" and
"tag2". My experience in trying to construct an EOQualifier that
accurately describes this requirement hasn't been good. Writing the
SQL that would select the correct locations makes my head spin :-)
Alexander Spohr's GROUP BY and HAVING is probably headed in the right
direction. The SQL might be something as ugly as the following
(totally untested and likely invalid :-)
SELECT t1.id FROM Location t1, LocationTag t2, Tag t3 WHERE t1.id =
t2.locationId AND t2.tagId = t3.id AND (t3.tag = "tag1" OR t3.tag =
"tag2") GROUP BY t1.id HAVING COUNT(t1.id) = 2
EOF can't generate such a query by default. However, the query
might suggest an EOF strategy. You could fetch all Locations whose
tags.tag array contains a certain tag value. Then repeat the fetch
for each different tag value. Concatenate the fetched Locations into
a single array, sort by Location, then iterate the array keeping any
Location whose count in the array is the same as the number of
different tag values. Ugly! Anyone else have a better suggestion?
Aloha,
Art
_______________________________________________
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