Hello Capt Fanning:
Do you know what the SQL would be for that type of query?
Would it be Select ProjectId, Project Name,etc from Project where projectId
NOT IN (select projectId from MileStone) ??
If it is, you can try using a EOSQLQualifier as follows
EOEditingContext *ec=[self defaultEditingContext];
EOSQLQualifier *sqlQualifier = [[EOSQLQualifier alloc]
initWithEntity:[ec entityNamed:@"Project"]
qualifierFormat:@"%A NOT in (Select projectId from Milestone)",
@"projectId"];
EOFetchSpecification *fs=[EOFetchSpecification
fetchSpecificationWithEntityName:@"Project"
qualifier:sqlQualifier sortOrderings:nil];
NSArray *objects=[ec objectsWithFetchSpecification: fs];
Or if it is more complicated you can bypass the auto SQL generation for that
fetch and pass the SQL to the fetchspec in a hint dictionary.
-dave
Joe Fanning wrote:
> I'm trying to use the EOM Qualifier Builder to construct a Fetch Spec
> which needs to query across a to-many relationship specifically for the
> case where there are no destination objects.
>
> Say I have two tables: Project and Milestone. There are a variable number
> of milestones for each project so there is a to-many relationship:
> Project <--->> Milestone. The first milestone is "approval." It is easy
> enough to query on the keypath "toMilestones" to find all projects that
> have approval dates. However, I need to generate a list of projects that
> have not yet been approved, and so have no Milestone objects associated
> with them.
>
> I've tried:
>
> toMilestones.date = nil
>
> and
>
> toMilestones = nil
>
> to try and get a hit due to the absence of destination objects. And I've
> tried:
>
> toMilestones.milestone <> 'APPROVED'
>
> to try and get a hit for the lack of a destination object with an
> APPROVED status.
>
> Any suggestions? Something along the lines of my last example above would
> be nice since it is conceivable that sometime in the future there might
> be milestones accomplished without the project being appoved. In any
> event, the query needs to handle the case where there are no destination
> objects to query against. I'm sure it's something obvious, but that's
> what we new guys do...miss the obvious.
>
> Thanks,
> Joe