retrieve if Count = Count

0
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? https://docs.mendix.com/refguide7/xpath-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. https://www.youtube.com/watch?v=sdabUY-w4ZU            
asked
2 answers
1

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:

 

[M.OrderLineDraft_Order/M.OrderLineDraft]
[not(M.OrderLineDraft_Order/M.OrderLineDraft[not(M.OrderLine_OrderLineDraft/M.OrderLine)])]

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:

image.png

answered
1

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. 

answered