Hi,
Got a couple of question on using Calculations:
-
Can I savely use databaseManager.hasRecords(relation) inside an (unstored) calculation?
-
Per table in my solution, I have to store an ID, used in relations. As far as I can see: two options: create a global variable per table, or create an (unstored) calculation on every tabel, with a simple “return x;” (x being an integer). What are the pro’s and con’s of both solutions, performance wise? (From a coding perspective, I like the calculations more.)
Hope someone can shed some light…
Paul
-
NO. If you can’t see it in the “tree” in the calculation dialog, then you cannot use it in a calculation.
-
I would use a global. Globals are in-memory variables - whereas unstored calcs have to be evaluated and returned.
Why are you using one per table? Is it something like the “currentID” or something like that?
hi Bob,
Regarding 1: It does work though… question was if it’s save to use…
Regarding 2: In my solution there are certain tables containing records that are linked to multiple other tables. for example the translation table. it holds translations for records of multiple tables. Based on the Id stored agains a table and the tableId column in my translations table, I can find the right record.
Here’s the content of my Calculation (on the products table)
if(databaseManager.hasRecords(products_to_translations))
{
return products_to_translations.translationtext;
}
else
{
return productname;
}
And the realtion from products to translations is defined as follows:
products.productsID = translations.entityid
products.tableid (= Calculation) )= translations.tableid
globals.application_language (global with current language) = translations.languagekey
Paul
Hi Paul,
Regarding #1 - if it’s not in the tree - it’s NOT SAFE. DO NOT DO IT.
Hopefully that’s pretty clear. Your performance will suffer terribly!
Regarding #2 - I sort of get it. Can’t you use i18n for that stuff?
Hi Bob,
regarding #1: I think I get it ![Very Happy :D]()
regarding #2: I’ve been looking at that, but since I18N has a key that consists of only one column/field, it’s not very neat.
I’d have to concatenate the key on the search side on the fly, by concatenating products.productsID, products.tableid and globals.application_language into one string and store the translations against such a key.
Question is: Will that be faster? Won’t the search for the I18N text, that comes from the DB as well, be triggered just as much as the wrong solution I currently use?
Anyone else have neat design tricks for this issue? ![Very Happy :D]()
Paul
hi Bob,
Seems I solved my own problem ![Wink :wink:]()
Got two options:
var text = products_to_translations.translationtext;
if (text != null)
{
return text;
}
else
{
return productname;
}
Both should be “legal”, so my issue is solved ![Smile :)]()