Have you checked out ERXEOControlUtilities.aggregateFunctionWithQualifier? 
Sounds like it might suit your needs.

- hugi



> On 23. ágú. 2016, at 14:34, [email protected] wrote:
> 
> Thanks a lot (Samuel too).
> 
>> On 22. 8. 2016, at 8:29 PM, Chuck Hill <[email protected]> wrote:
> ...
>> I can’t think of a way to do that that isn’t a lot of code and prone to 
>> inconsistencies with the relationship data.
> 
> Hmmm... is there at least some WO or WOnder trick, which would fetch at 
> SQL-level a sum for relationship on-demand, i.e., something like this 
> fetchSumForAttributeInRelationsip hypothetical method:
> 
> ClassA eo=...; // an enterprise object of entity A
> Number sum=eo.fetchSumForAttributeInRelationsip("x","ab")
> 
> which would _not_ fire the "ab" relationship fault; instead, it would 
> generate and perform an SQL similar to "SELECT SUM(C_X) FROM B_TABLE WHERE 
> ..." (with appropriate WHERE to get those rows of B which are in the 1:N 
> relationship "ab" from "eo")?
> 
> Or do I have do go explicitly create and run the SQL expression 
> programmatically?
> 
> Thanks,
> OC
> 
>> From: <[email protected]> on behalf 
>> of OC <[email protected]>
>> Date: Monday, August 22, 2016 at 6:36 AM
>> To: WebObjects-Dev Mailing List <[email protected]>
>> Subject: derived attribute to sum a relationship?
>> 
>> Hello there,
>> 
>> is there a way to define a derived attribute to sum a relationship's 
>> attribute?
>> 
>> Presumed I have
>> 
>> - entity A with PK column C_ID, relationship:N "ab" leading to entity B
>> - entity B with FK column C_A_ID (which forms the relationship) and integer 
>> column C_X representing attribute "x"
>> 
>> is it possible to define a derived attribute "abSum" of A, which would sum 
>> all "x"'s of those B rows, which are -- through their C_A_ID foreign key -- 
>> related to a row in A?
>> 
>> Normally, of course, I would implement it Java-side, like this
>> 
>> ===
>> class AEntityClass ... {
>>  int abSum() {
>>    int s=0; for (b in ab()) s+=b.x; return s
>>  }
>> }
>> ===
>> 
>> but this time, I would need to do that SQL-side, for (a) speed, (b) memory 
>> (so that all B rows do not need to be fetched), (c) so that the attribute 
>> can be used in qualifiers when fetching, e.g.,
>> 
>> ===
>> NSArray objs=ec.objectsWithFetchSpecification(new 
>> EOFetchSpecification("A",EOQualifier.qualifierWithQualifierFormat("abSum > 
>> 100",null),null))
>> ===
>> 
>> I have tried to define it as the most obvious "select sum(bt.C_X) from 
>> B_TABLE bt where bt.C_A_ID = C_ID", but I bumped into numerous problems, 
>> from ambiguity of C_ID up to the fact that EOF caches the fetched value and 
>> does not recache when the relationship objects change, and thus I am getting 
>> obsolete values.
>> 
>> Is there a way to do that properly?
>> 
>> Thanks,
>> OC
>> 
>> 
>> _______________________________________________
>> 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/chill%40gevityinc.com
>> 
>> This email sent to [email protected]
> 
> 
> _______________________________________________
> 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/hugi%40karlmenn.is
> 
> This email sent to [email protected]


 _______________________________________________
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