In my view, I need to loop over this query and run another query.
What is the best way to do this? I'm trying to avoid having any
<cfquery> or <cfstoredproc> calls in my view as it just seems old
school, but I need to loop over this query and use a value from one of
the columns in this inner query. Is there a more elegant way to do
this?
You could set a reference in the prc to the service method that runs
the query in your handler and then pass in the arguments you need from
prc.qData loop by calling the function from the prc scope.
I did notice that any properties that were injected into my Service
like the DSN don't seem to be available when doing it this way
though. At the top of my service I have this:
I would prepare the data before-hand. So, have a separate service call which gets your original data, loops over it, calls another service within each loop and manually populate a new query with queryAddColumn etc. Then pass this new query down to your view.
It depends if the nested query is bringing back multiple records or not.
If it’s always going to be 1 row of data, you could just manually add the new fields to the original query.
If it’s going to be multiple rows, then you could add the nested query into a new field of the original query, but yes, this means you would have to loop over the nested data in the view.