Derived attributes never update until you do a refreshing fetch.  So while you 
can sort of do this, derived attributes will never meet your needs here.

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.

Chuck

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]<mailto:[email protected]>)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/chill%40gevityinc.com

This email sent to [email protected]<mailto:[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