• 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
Re: derived attribute to sum a relationship?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: derived attribute to sum a relationship?


  • Subject: Re: derived attribute to sum a relationship?
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 22 Aug 2016 18:29:04 +0000
  • Thread-topic: derived attribute to sum a relationship?

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: <webobjects-dev-bounces+chill=email@hidden> on behalf of OC <email@hidden>
Date: Monday, August 22, 2016 at 6:36 AM
To: WebObjects-Dev Mailing List <email@hidden>
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@hidden)

Help/Unsubscribe/Update your Subscription:

 

This email sent to email@hidden

 _______________________________________________
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: "email@hidden" <email@hidden>
References: 
 >derived attribute to sum a relationship? (From: OC <email@hidden>)

  • Prev by Date: in memory like qualifier using collation
  • Next by Date: Adding allowed attribute to built in element validation
  • Previous by thread: derived attribute to sum a relationship?
  • Next by thread: Re: derived attribute to sum a relationship?
  • Index(es):
    • Date
    • Thread