In a Servoy solution, often you have a record and you want to access a record that is related via an n:1 relation. Say, for example, you have a relationship from contacts to companies. You are working with a contact record, and you need to fetch the related company into a variable to work with.
The proper way to do this is first to test for the presence of a record, and then fetch it through the relation you have defined. If it's something you're going to do often, you can wrap that logic in a dataprovider calculation on the contacts table, however. Try defining a "MEDIA" type calculation something like this:
-
function get_company()
-
{
-
return databaseManager.hasRecords(contacts_to_companies) ? contacts_to_companies.getRecord(1) : null;
-
}
Then, when you need to access the related record in code, use that calculation instead of reproducing the logic to fetch the related company....like:
-
var contact = foundset.getRecord(foundset.getSelectedIndex(); // fetch a contact from anywhere
-
var company = contact.get_company;
I find this a very handy shortcut to have around and try to define a "get_xxx" method on all my child tables that allow me to fetch the related parent in the relation.