One to many in a calculation

I have a one-to-many relation. The goal is to display all matched dataproviders in a calculation as a string.

So far I used the following code which works.

function string_joint()
{
	var name = databaseManager.getFoundSetDataProviderAsArray(person_root_to_pers_name,'d_pers_name'); 
	var j_names = name.join(' ')
	return j_names	
}

But it looks that this is not the way to be supposed to do with servoy 8.1 Can someone give me a light how this can be achieved ? I’ve tried to do it by using an array and join it. But I receive only one matching field and not many since there were some.
I use this function for displaying the first name and the surname of a person. One table holds the "identity’ of the person and the other table the name data.

Thanks for helping me.

I think that method has long been deprecated. You can loop over your related foundset instead, e.g.

function string_joint()
{
   var names = [];
   for ( var i = 1; i <= person_root_to_pers_name.getSize() ; i ++) {
      names.push(person_root_to_pers_name.getRecord(i).d_pers_name);
   }
   return names.join(' ');
}

That works fine. So many thank’s for your help.

Dominique Kull

As you have the separator defined as blank, you need to rely on the fact that all names have no blanks inside, I guess, which might be not the case always.

And when you use that function as a table-based-calculation, it might be better to externalize it if possible, as the operation is a bit costly due to database operations and you can not really control when a table-based-calculation is called.

Bernd.N:
As you have the separator defined as blank, you need to rely on the fact that all names have no blanks inside, I guess, which might be not the case always.

It’s a join, not a split… so this will never be an issue.

patrick:
I think that method has long been deprecated.

Easy replace is this:

function string_joint()
{
   var name = databaseManager.convertToDataSet(person_root_to_pers_name,['d_pers_name']).getColumnAsArray(1); 
   var j_names = name.join(' ');
   return j_names;
}

EDIT: sorry… just noticed you’re referring to calculations here
databaseManager functions are no longer available in calculation-mode since some versions.
So the loop would be your only option, however: using relations in calculations is not recommended as it can slowdown your application big time.

It’s a join, not a split… so this will never be an issue.

Yes I know, but the resulting string will have some meaning for some other function usually, which will assume that all strings that are separated by a blank are separate names.
So Mr. Doe Meyers will result in two persons for any following functions.

Note that Servoy will check which data is touched in your calculation.
When calling databaseManager.getFoundSetDataProviderAsArray Servoy does not detect you are using the d_pers_name fields, so the calculation will not refresh on changes.

When you use Patrick’s loop, it will detect changes on the values and the calculation will automatically update.

Rob