Adam Cameron
week = queryNew("id,en,mi", "integer,varchar,varchar", [
[1,"Monday","Rāhina"],
[2,"Tuesday","Rātū"],
[3,"Wednesday","Rāapa"],
[4,"Thursday","Rāpare"],
[5,"Friday","Rāmere"],
[6,"Saturday","Rāhoroi"],
[7,"Sunday","Rātapu"]
])
week.some((row, i) => {
writeOutput("In loop #week.currentRow# [#i#]<br>")
//return i == 5 // this works fine on CF
return week.currentRow == 3 // this does not: it's always 1
})
currentRow
does not get incremented as the query is iterated over; it's always 1
. Lucee behaves how I'd expect.cfvonner
10/06/2022, 4:49 PMi
in your example) should return the currentRow
value.
I will say that Adobe's examples, while correct, are confusing for a newbie as they both define the closure outside the some
call and use the new arrow syntax. While both things are completely valid and might be good syntactic "sugar", they make it hard for someone just learning about querySome()
or .some()
for the first time to follow.Adam Cameron
Adam Palcich
10/06/2022, 5:21 PMweek.currentRow
be expected to return 1 when not being looped over? Is your code trying to set the default `currentRow`for week
via your some()
function? Apologies again if I'm completely misunderstanding the issue.cfvonner
10/06/2022, 5:44 PM.some()
function does indeed return a boolean. However, inside the closure (the first argument passed inside .some()
) you should have access to the row
, currentRow
, and the entire query
. This is in keeping with how CF handles all of these higher-order functions related to queries (and similar to higher-order functions for other data types).Adam Palcich
10/06/2022, 6:09 PMsome()
.
On line 18 of your example, outside of your some()
function, you have writeOutput("After loop #week.currentRow#<br>")
. Wouldn't this just be 1 as long as there was even a single row in your query (otherwise it'd be 0)? Is the problem that this code (line 18) is returning 1 and you were expecting 3?Adam Palcich
10/06/2022, 6:18 PMAdam Cameron
some
instead of each
: I wanted to early-exit the iteration process, and examine where the row pointer ended up being.
I was hoping CFML would maintain the currentRow reference having prematurely broken out of a loop. I had originally checked on <cfloop>
, and just wanted to see if the iteration higher order functions behaved any differently. They always reset it 😐Adam Cameron
<cfloop query="week">
and I broke out of it on the third row, I would dearly like currentRow
to still be 3
outside the loop, afterwards. Not the case.Adam Palcich
10/06/2022, 6:23 PMAdam Cameron
cfvonner
10/06/2022, 9:02 PMquery.currentrow
) while inside of the higher-order functions. For some reason I wasn't thinking "loop" (where I have always previously used the query.currentrow
metadata attribute). Thank you @Adam Cameron for opening my eyes to what, in hindsight, should have been somewhat obvious! 😄 Although clearly that doesn't work in ACF. 😢mtbrown
10/06/2022, 10:42 PMcurrentRow
. This seems especially fraught when executing in parallel. If you need the row number, that's what the second argument is for.cfvonner
10/07/2022, 12:15 AMaliaspooryorik