.unionAll not receiving arguments passed to function

query.from( "users" )
    .select( "name" )
    .where( "id", "=", { value = arguments.id, cfsqltype = "varchar" } )
    .unionAll( function( q ) {
        q.from( "users" )
            .select( "name" )
            .where( "id",  "=", { value = arguments.id, cfsqltype = "varchar" } );
     } );

This should work correct? When I call this, Whoops tells me Element ID is undefined in ARGUMENTS. But only within the .unionAll the first .where is passed the argument.

The unionAll is inside a closure, so the arguments scope has changed. Remove the arguments prefix from the id inside the closure to fix it.

There is currently no way in CFML to prefix a variable that comes from a parent arguments scope. You just have to leave it off and let it discover it.

1 Like