« [Tip] Email plugin: dynamic SMTP authentication | Main | [Tip] Email plugin: sending attachments »
July 14, 2005
[tip] How to avoid errors on relations
by Marcel Trapman
www.it2be.com
Have you ever seen that yellow triangle on the left of your window statusbar on record selection? Huh... You didn't... Then please skip this tip, otherwise read the below...
9 out of 10, if this occurs on record selection and you have calculated fields with relations in them for the table the form is based on, this is due to a non-exiting relation you point to without a check.
Checking a relation can be done in the following ways:
if (table_to_second_table)
if you do this you only check if the relation is there...
if (table_to_second_table.getSize())
if you do this you only check if there are any records
pointing to a row in the relationship 'table_to_second_table' while only performing the first check without the second will give an error if there are no records. So, you will have to do both:
if (table_to_second_table && table_to_second_table.getSize())
this is the only correct one but quite a job to perform to perform this on every relation. Therefor the kind people of Servoy gave us the following function:
databaseManager.hasRecords(). This function can be called instead of the above code when writing our methods. When we write a calculated field we can not access the databaseManager and therefor we also have the function utils.hasRecords(). In fact they both do the same job...
I made it a good habit to even check on the existance of a relation even if I am 100% sure it is there. Better save than sorry...
Cheers and have fun working with Servoy,
Marcel
| Posted by IT2Be on July 14, 2005 at 05:45 PM in Tips | Permalink