Forum Discussion
Hi Michael,
Thank you for the quick reply. I have tried this solution and the query was accepted by AML Studio without errors but returned incorrect results — ex: Count of 70 items (All the items) when the expected result of items is around 5. It appears that related_id returns nested <Item> nodes rather than scalar GUIDs, so the id condition="in" filter does not match correctly.
I ended up using a two-step approach which works but it needs to do an additional server call.
- Query the relationship type to collect the related IDs
- Inject those IDs as literal GUIDs using where="ItemTypeB.id IN ('GUID1','GUID2',...)" on the root query
This gives the correct filtered results and also allows other AML filters (e.g. Relationships) to AND correctly alongside the ID filter.
Let me know if this is the right approach. My intention was to do this in a single server call but instead I have to make two round trips. Is there a supported AML syntax that can achieve this in one call?
Hello,
I don’t think this can be achieved reliably in a single AML call.
Relationships in AML are always evaluated from the source (parent) side, and source_id / related_id are just reference properties, not join operators. Because of that, AML does not support filtering items from the related side using conditions on the source item.
A common approach is to implement a server-side method that performs the intermediate query and returns the final result in a single call.
Regards,
Michael
- angela13 days agoCatalyst II
Interesting use case! Is the final goal one AML query for the BatchLoader? Or an AML query in a Method?
Inside a Method you have a bit more freedom. You can make a for-loop to build your WHERE part with the help of many many logic or´s.
Based on Michaels example you would and up with something like this:
<Item type="ItemTypeB" action="get">
<id condition="in">
<Item type="RelationshipType" action="get" select="related_id">
<source_id>
<or>
<Item type="ItemTypeA" action="get" select="id">
<some_property>value</some_property>
</Item>
</or>
<or>
<Item type="ItemTypeA" action="get" select="id">
<some_property>value2</some_property>
</Item>
</or>
<or>
<Item type="ItemTypeA" action="get" select="id">
<some_property>value3</some_property>
</Item>
</or>
</source_id>
</Item>
</id>
</Item>
Code not tested, probably contains bugs. But I use this OR-technique on a more or less frequent basis inside Methods for mass validation use cases.