Aggregating over an indirect relationship

Release notes for Servoy betas

Aggregating over an indirect relationship

Postby Neale » Mon Aug 04, 2003 4:36 pm

This time I'm trying to aggregate over an indirect relationship - i.e. I have tables a, b & c where c is child of b and b is child of a.

In a form displaying table a, I need to display the aggregate of an indirectily related field in table c. What is the correct/recommended way of handling this in Servoy?

Thanks,
Neale.
Neale
 
Posts: 230
Joined: Thu May 15, 2003 6:29 am
Location: Australia

Postby Jan Blok » Tue Aug 05, 2003 9:53 am

It can be done with:
1) create calculation with "return relation_a_to_b.relation_b_to_c.aggregatename;" and place this calc on your form
This one is not yet explained in the manual because you cannot 'move' this construct from the tree/list, but you have to type it yourselfs (this works many relations deep)

2) place the aggregate as related field in tabpanel
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam

Postby Neale » Tue Aug 05, 2003 3:33 pm

Nice solution :-)

But, I think I missed something re using a tabpanel (and clearly it doesn't work without it) - could you please elaborate on this point.

Thanks,
Neale.
Neale
 
Posts: 230
Joined: Thu May 15, 2003 6:29 am
Location: Australia

Postby Jan Aleman » Tue Aug 05, 2003 6:05 pm

Jan Blok was slightly mistaken (it's hot currently in Europe 8) ), what he mentions only applies to non-aggregate values.

To aggregate over multiple relations you have to use a SQL query, for example:

Code: Select all
select sum(t3.numb) from t1,t2,t3 where t1.t1 = t2.t1 and t2.t2 = t3.t2 group by t1.t1;


To get the results of this query onto your form do the following:
1. create a label and place it where you want to see the results. Fill in the name property of the label (to make it show up in the method editor)
2. create a method that says:
Code: Select all
var query = "select sum(t3.numb) from t1,t2,t3 where t1.t1 = t2.t1 and t2.t2 = t3.t2 group by t1.t1";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
elements.labelxxx.text = dataset.getValue(1,1);


replace labelxxx with the name you gave to the label earlier

Add this method to the onRecordSelection event so it will be triggered each time the record is selected.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Neale » Wed Aug 06, 2003 2:57 am

Ah, thanks for the clarification - it works OK :-)

I presume that if I want to apply formatting (the sum is a money value) then I should either display it in a field (via a dataprovider which is a global var) -OR- do the formatting in JS (i.e. there appears to be no way to format the label text)?

This also brought up a method form/foundset/navigation query, which I'll take up separately.

Thanks,
Neale.

PS: comiserations on the "heatwave" - I guess that's like us here complaining that some weeks our daily maximums aren't much above ten degrees!
Neale
 
Posts: 230
Joined: Thu May 15, 2003 6:29 am
Location: Australia

Postby Jan Aleman » Thu Aug 07, 2003 12:51 pm

correct, alternatively you can also format the number in your sql statement.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth


Return to Latest Releases

Who is online

Users browsing this forum: No registered users and 14 guests