Bernd.N wrote:Am I right that this will basically fire a SQL COUNT(*) to decide the hasRecords-question?
Because I wonder why I do not see such a COUNT() in the SQL performance log on the AppServer.
Your assumption is not correct.
Servoy will fire a full SELECT as if you were requesting the related foundset.
So this:
- Code: Select all
utils.hasRecords(project_elements_to_supplier_invoices)
will have the same backend impact as:
- Code: Select all
var _fs = project_elements_to_supplier_invoices; var _bHasRecords = _fs.getSize() > 0
Will the 'utils.hasRecords' function have to much impact on performance? I wouldn't say so.
Most of the times you'll use this function to check if you need to perform an action on / read data from the related foundset.
As executing 'utils.hasRecords' will make Servoy cache this particular foundset, the query won't be executed twice in the back-end.
Depending on the relation you could prevent he application server to execute the query.
So in case of a relation 'project_to_client', you would have the client_id as a FK in the table projects.
- Code: Select all
if(client_id && utils.hasRecords(project_to_client)) {
application.output('This project is for a client!');
}
The above code will already stop the evaluation in the 'if' statement as soon as the client_id doesn't contain a value.
Hope this is clarifying things.