I have a table that showed the type of coaching and a reference field that shows the individuals who practice the coaching types. I am trying to show a table that shows the coaching types and the number of people against each coaching type.
Here is the code I have. I am not sure where is going wrong so the the new property is not generated (totalCoaches was never added to the item). When I use console log to check the results, they were logged though the results were far more than the number of IDs which is really weird. If anyone knows how to fix this or a better way to do this, please shed some light. Thanks!
import wixData from ‘wix-data’;
export function CoachingAreas_afterQuery(item, context) {
item.totalCoaches = findNumCoaches(item._id);
return item;
}
const findNumCoaches = (id) => {
wixData.queryReferenced(“CoachingAreas”,id,“coachName”)
.then( (results) => {
return results.totalCount;
} )
. catch ( (error) => {
console.log(“incorrect”);
} );
};