Given it’s searching on the total of related records, any implementation is going to be unstored and so potentially quite slow depending on how you implement.
On products, create a calc, call it something like total_orders
on orders table, add an unstored calc, call it “foundCount” and set it to Get ( FoundCount ) - make sure it’s unstored.
Back on the total_orders, just reference the “foundcount” field through the relationship from products to orders. This will give you the count of records through the relationship.
Note that the result is obviously unstored, and so while you can search it, the relationship has to be evaluated for every product record in order to determine a result.
If you plan on using this a lot moving forward, I’d suggest storing the total orders on the product record, so that searching specifically is much faster (if you purely want to display the total, you don’t need to store it, but searching is another story..)
Easiest way is change your “total_order” calc to instead be an auto-enter calculation. Same result, but modify the calc slightly:
Let ( ~triggerField = refresh_field ; Products::foundcount )
It is referencing a new field called “refresh_field” which is simply a number field you can add. The reason I do it this way is so anytime I want the total orders value updated, I simply need to set “refresh_field” to 1. It is a nicer way to trigger the auto enter than having to always actually calculate the # of orders and store that. - let the auto enter do that work for you from its context.
… Anyways with that said, the pitfall of storing the value is you need to ensure it is updated. So the value of “refresh_field” would need to be set to 1 in circumstances like:
• New order raised for product
• Order deleted
If you use things like order statuses, and do not wish to include cancelled orders, you might need to simply adjust the relationship to include a predicate that excludes cancelled orders…