Hi Markus,

The problem is that you can’t do what you are trying to in one step because 
there are likely several DocumentText objects that match each of your criteria 
which is going to cause the problems you are seeing. 

You will have to evaluate the criteria one at a time, but first you have to 
figure out which criteria can combine into single Qualifiers/Clauses, and which 
have to be evaluated independently.

I find it much easier to create each qualifier individually, using descriptive 
of names as possible, then combine them together so it all reads as a sentence. 
It helps make complicated qualifiers like this more obvious to write, and later 
come back and read.

>  all Documents where the assignment to Text "A" has comment "x” 

seems like criteria that can be combined like so:

>  assignment to Text "A"  

ERXKeyValueQualifier thatAreForTextA = DocumentText.TEXT.eq(“A”)
> has comment "x” 

ERXKeyValueQualifier thatAreForCommentContainsX = 
DocumentText.COMMENT.contains(“x”);
> assignment to Text "A" has comment "x” 

ERXAndQualifier thatAreForTextAandCommentContainsX = 
thatAreForTextA.and(thatAreForCommentContainsX);

Now we will create a qualifier for Document objects that are related to **at 
least one** DocumentText that match this set of criteria:
ERXExistsQualifier thatMatchTheFirstSetOfCriteria = new 
ERXExistsQualifier(DOCUMENT_TEXTS, thatAreForTextAandCommentContainsX);


>  AND the assignment to Text "B" has status "y”.
This also seems like criteria that can be combined.

>  assignment to Text "B" 
ERXKeyValueQualifier thatAreForTextB = DocumentText.TEXT.eq(“B”)
>  has status "y”.
ERXKeyValueQualifier thatAreForStatusY = DocumentText.STATUS.eq(“y”);
>  assignment to Text "B" has status "y”.
ERXAndQualifier thatAreForTextBandStatusY = 
thatAreForTextB.and(thatAreForStatusY);

Now we will create another qualifier for Document objects. This one will find 
instances that are related to **at least one** DocumentText that match the this 
second set of criteria:
ERXExistsQualifier thatMatchTheSecondSetOfCriteria = new 
ERXExistsQualifier(DOCUMENT_TEXTS, thatAreForTextBandStatusY);


Now comes the two-step part:

First, fetch the Document objects that are related to **at least one** 
DocumentText that match the *first* set of criteria:
NSArray<Document> documentsForTheFirstSetOfCriteria = 
Document.fetch(thatMatchTheFirstSetOfCriteria);

Now, filter the that array for ones that are also related to **at least one** 
DocumentText that match the *second* set of criteria
NSArray<Document> documentsForTheFirstAndSecondSetsOfCriteria = 
ERXQ.filtered(documentsForTheFirstSetOfCriteria, 
thatMatchTheSecondSetOfCriteria);

Done. “documentsForTheFirstAndSecondSetsOfCriteria" will have … wait for it … 
Document objects that match both sets of criteria!

Another way to write (in English) what this does is:

"The user wants to see all Documents that are related to at least one 
DocumentText that has a Text of “A” and a comment of “x” and the Documents must 
also be related to at least one DocumentText that has a Text of “B” and a 
status of “y”."

Dave Avendasora

On Dec 12, 2013, at 8:56 AM, Markus Ruggiero <[email protected]> wrote:

> Now comes the qualifier to retrieve Documents: The user sees a D2WQueryPage 
> for the document properties with an embedded property level query component 
> that presents the full list of possible DocumentText objects with their 
> status and comment fields. A typical scenario could be: the user wants to 
> enter a comment query for the second assigned text (that's Text "A") and/or 
> picks a query value for the status of the 7th assigned text (this could be 
> Text "B"). Upon executing the query the user expects to retrieve a list of 
> Documents that fulfill all given criteria. In this example the user wants to 
> see all Documents where the assignment to Text "A" has comment "x" AND the 
> assignment to Text "B" has status "y".
> 

—————————————————————————————
WebObjects - so easy that even Dave Avendasora can do it!™
—————————————————————————————
David Avendasora
Senior Software Abuser
Nekesto, Inc.





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to