Working with queries in data.js or on page

So I thought I was getting the hang of using queries and then I ran into an issue I can’t seem to find a relatively simple answer for (at least I assum the answer should be relatively easy). What I am attempting to do is laid out below.

I have a collection called “Clients” that has a “Client ID” field called clientId. I have a second table called “Machines” with the same “Client ID” field which I am currently filling in myself (will eventually use a form to do so).

On a dynamic page I am loading all the client data (it is an Admin page only I can access). I have a table on this page that shows some basic client info, but I want to add a column to this table for the number of machines in the “Machines” table. Below are the things I have attempted to no prevail (and not sure which one is considred the “right” approach).

  1. I tried using an after query hook on the “Clients” table thinking I could get the “Client ID” value for the item passed in, then run a query on the “Machines” table using this value in the filter, and use the .count() or totalCount properties/functions to get the total number of machines which I figured I could then put into the “Clients” collection by returning item.numberOfMachines (which is a field in the “Clients” table). I thought this would work as I have a an after query hook where I computer the machines name from other columns in the “Machines” table using a similar approach. However, nothing ends up in the column.

  2. After looking at the aggreagations example I figured I could go to the page that has the table on it, do as I did above (running a query on the “Machines” table using the “Client ID” from the dataset on the page as a filter in an (“#dataset”).onReady funciton). I’m pretty sure I have gotten this query to run properely, however, I’m not sure how to then put these values into every row of the table (this is where I got lost in the example since I’m not sure I need to call a funciton such as the monthSort shown in the example).