Discussion:
[Modeling-users] Aggregate values in objects
Kertis, Dennis
2004-08-12 15:30:24 UTC
Permalink
Is there a way I can get a field populated with an aggregate value. i.e., I
want a manager to have a field which would contain how many employees work
for him by doing a select count(*). I parsed through the fetching section
of the doc and didn't find a way to do this.
Sebastien Bigaret
2004-08-12 20:33:04 UTC
Permalink
Post by Kertis, Dennis
Is there a way I can get a field populated with an aggregate value.
i.e., I want a manager to have a field which would contain how many
employees work for him by doing a select count(*). I parsed through
the fetching section of the doc and didn't find a way to do this.
For COUNT(*) there is a dedicated method: EC.fetchCount(), which
has the very same syntax as EC.fetch() and returns the number of
objects matching the qualifier.

I recommend that you define a method returning this count, rather
than have an integer field populated with such a value, or else
you should be prepared to deal with every possible situations
where this count can change if you do not want that this field's
value get out of sync.

Other aggregates are not yet supported; I believe we formerly
discussed this here, probably with Ernesto, among others.
I do not have access to the archives here, Erny could you maybe
confirm?

-- Sébastien.

Loading...