Using Relations in Calculations
Posted: Sat Mar 02, 2019 10:43 pm
Consider the following table (columns) setup:
books (id, name), tags (id, name), booktags (book_id, tag_id)
When showing a list of books, I also want to show the tags that apply to that book. So I added a calculated field 'tags' to the books table:
The cnt value is the correct number for the selected book. But in the for loop the rec variable is always the first record of the related foundset. I end up with an array of the correct length but all items are the first tag in the list.
Is it not possible to use relations inside calculations in this way?
books (id, name), tags (id, name), booktags (book_id, tag_id)
When showing a list of books, I also want to show the tags that apply to that book. So I added a calculated field 'tags' to the books table:
- Code: Select all
function tags(){
var aTags = [];
var rec
var cnt = books_to_booktags.getSize();
for(var i = 1; i <= cnt; i++){
rec = books_to_booktags.getRecord(i);
aTags.push(rec.booktags_to_tags.name);
}
return aTags.join();
}
The cnt value is the correct number for the selected book. But in the for loop the rec variable is always the first record of the related foundset. I end up with an array of the correct length but all items are the first tag in the list.
Is it not possible to use relations inside calculations in this way?