retrieve if Count = Count

Hi community,   1. I am trying to retrieve Order objects, where ALL the InvoiceLineDraft children have a 1-1 to InvoiceLines. And also more then 0 invoicelineDrafts.   Order 1-* InvoicelineDraft InvoicelineDraft 1-1 Invoiceline   2. The documentation refers to Xpath Count. (could this be used)? if count = count?   3. Do I need to 'compare' as this seems like id need to retrieve everything, then compare, which seems a bit heavy?   Also for who ever else gets stuck on XPath, I recommend watching the 8min vid by Willem van Zandvoort.            
2 answers

You can't use the count function in a regular XPath in a Retrieve Action (see the documentation for Mendix 9, which clears this up here).


Fortunately, you don't have to count, you simply want to know if at least one exists, and if a condition holds for all children. You can rephrase your query as:

* All Orders which have at least one InvoiceLineDraft

* No InvoiceLineDraft of an Order has no InvoiceLine


The resulting XPath is:



Note that this XPath has two not() functions over association, which is a performance risk, if you have many objects.


I have used this domain model:



To add to Rom's answer - for performance reasons, in many cases instead of retrieving over a "not" association, it's more performant to first retrieve the list of all orders, then retrieve the list of all orders that have an association, and then subtract that list from the list of all orders.