Is there a better way of counting number of elements in a relation #862
AlfonsoRReyes
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have been playing with row formulas for couple of days. db-folder is fantastic.
I created a function to calculate the number of elements that are selected in a relation column and got something like this:
The relation column
![image](https://user-images.githubusercontent.com/19330646/228624757-1a6fefa6-f10d-4e6b-bcc9-fa49bcffba4c.png)
lec_tur_rel
looks like something like this:Row 1 contains two tutorials; row 2 contains 2 tutorials; and row 3 contains three.
The formula in the column
NumTutorials
is${db.js.numElements(row["lec_tut_rel"])}
.The formula works fine; I get the results I need. But when I print the results to the console.log it seems that the formula is running as many times as the number of rows, which seems to be correct but inefficient. You may think you could this simpler by using the formula
${row["lec_tut_rel"].length}
, but it will not work; it will only return the number of elements in the relation of the first row, and the rest of the rows will be empty.Could someone recommend a better function?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions