• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
derived attribute to sum a relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

derived attribute to sum a relationship?


  • Subject: derived attribute to sum a relationship?
  • From: OC <email@hidden>
  • Date: Mon, 22 Aug 2016 15:36:32 +0200

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: derived attribute to sum a relationship?
      • From: Chuck Hill <email@hidden>
  • Prev by Date: Re: Using qualifier to filter related objects
  • Next by Date: in memory like qualifier using collation
  • Previous by thread: Re: how to enable secure session cookies?
  • Next by thread: Re: derived attribute to sum a relationship?
  • Index(es):
    • Date
    • Thread