On 08/07/2007, at 11:53 AM, Miguel Arroz wrote:

I need to build a complex fetch spec to solve a weird problem. Here's the part of the model that matters:

+-----+        +-----+        +------+        +------+
|  R  | <--->> |  A  | <--->> |  AP  | <<---> |  QO  |
+-----+        +-----+        +------+        +------+
                                 ^
                                 ^
                                 |
                                 |
                                 V
                               +------+
                               |  QP  |
                               +------+

My goal it to count the Rs in a given situation (it's the same as fetching them, but I'm using Wonder to count instead of fetch). And the crieria I want is:

1) All Rs where I have an APs with aValue property = "x" and QO = "qo" and QP = "qp". 2) All Rs where I have an APs with aValue property = "y" and QO = "qo2" and QP = "qp2".

(each R will have only one AP for condition 1 and one AP for condition 2)

It'll be more helpful if you can talk about the keys you're after within QO, QP, etc.

Here's my initial assumptions:
- the relationship from R to A is 'as', and from A to AP is 'aps', seeing as they're both toMany relations...
- by QO = "qo" you mean "as.aps.qo" contains (QO)qo1
- by QP = "qp" you mean "as.aps.qp" contains (QP)qp1.
etc

Yes?

So something like...
QO qo1, qo2; // assume these exist
QP qp1, qp2; // assume these exist
EOQualifier x;
EOQualifier y;

x = new EOAndQualifier(new NSArray(new Object[] {
new EOKeyValueQualifier("as.aps.aValue", EOQualifier.QualifierOperatorContains, "x"), new EOKeyValueQualifier("as.aps.qo", EOQualifier.QualifierOperatorContains, qo1), new EOKeyValueQualifier("as.aps.qp", EOQualifier.QualifierOperatorContains, qp1)
}));
y = new EOAndQualifier(new NSArray(new Object[] {
new EOKeyValueQualifier("as.aps.aValue", EOQualifier.QualifierOperatorContains, "y"), new EOKeyValueQualifier("as.aps.qo", EOQualifier.QualifierOperatorContains, qo2), new EOKeyValueQualifier("as.aps.qp", EOQualifier.QualifierOperatorContains, qp2)
}));


I want to AND those two conditions. In practice, I have two sets of APs, and I want the Rs' that are in both sets (the intersection of Rs).

new EOAndQualifier(new NSArray(new Object[] { x, y }));

Any ideia how to do this? I think the solution may be ERXQualifierInSubquery, but I couldn't make it work (specially because the "3 argument constructor" is actually a 4 argument constructor...).

Never used it, so can't help you there.

My problem is that making a qualifier for R with the format "a.ap.qo = %@ and a.ap.qp = %@ and a.ap.aValue = %@" wouldn't work, because I would not be selecting the same AP, right?

You need to use EOQualifier.QualifierOperatorContains when crossing toMany relationships rather than EOQualifier.QualifierOperatorEqual.

I'm saying that I want Rs with an AP with a certain QO, and an AP with a certain QP but i'm not saying they MUST be the same. Please please give me some hints, I really need to make this work. If you want more details just ask, it's almost 3am here and my mind is really confused with this.

Does the above help at all?

with regards,
--

Lachlan Deck

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

This email sent to [EMAIL PROTECTED]

Reply via email to