Counting related items

  • Posted 2 months ago

I am trying to automatically update a numeric field on a Parent Dish that tracks the total number of Published Menu Items linked to it.
This ensures that whenever a vendor adds, removes, or modifies a menu item, the parent Dish’s “Menu Items Count” field is always accurate for sorting and display.

Here’s what I have in terms of code snippet.. I’ve been working on this for over 3 days but stuck as it is not working.

https://gist.github.com/theudara/76c65e436149f098b326b2cb7a4afc70

Any help or guidance would be greatly appreciated.

  • Images