is there a way to define a derived attribute to sum a relationship's attribute?
- 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
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?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Help/Unsubscribe/Update your Subscription: