rneuber1 - Tuesday, November 16, 2010 9:47 AM:
I would like to retrieve some items using relationships as a search criteria.
For Example I have 3 items A,B,and C, with Relations A->C, A->B, and B->C. Now for a C item (identified by id or property 'item_number') I need all A items that are linked to C either directly (A->C) or indirectly (A->B->C).
This works well:
<AML>
<Item type='ITEM_TYPE_A' action='get' select="name" >
<Relationships>
<Item type=REL_A_C' select="related_id" action='get'>
<related_id condition="is not null">
<Item type="ITEM_C" action="get">
<item_number>TESTP-000004</item_number>
</Item>
</related_id>
</Item>
</Relationships>
</Item>
</AML>
Now I would like to retrieve items depending on more than 1 relationship, so I tried:
<AML>
</Relationships>
<Item type='ITEM_A' action='get' select="name" >
<Relationships>
<Item type='REL_A_C' select="related_id" action='get'>
<related_id condition="is not null">
<Item type="ITEM_C" action="get">
<item_number>TESTP-000004</item_number>
</Item>
</related_id>
</Item>
<Item type='REL_A_B' select="related_id" action='get'>
<related_id condition="is not null">
<Item type="ITEM_B" action="get">
<Relationships>
<Item type='REL_B_C' select="related_id" action='get'>
<related_id condition="is not null">
<Item type="ITEM_C" action="get">
<item_number>TESTP-000004</item_number>
</Item>
</related_id>
</Item>
</Relationships>
</Item>
</related_id>
</Item>
</Item>
</AML>
Unfortunately, if one of the relationships does not exist (e.g. the query results in an empty set), I get an error.
Is there a way to construct an AML query so that I get all A items (and only once each), for which at least one of the relations pictured above holds true?
Ralf
Brian - Thursday, November 18, 2010 4:23 AM:
Hi Ralf,
I don't think there is a way of doing what you want in a single AML query.
Since you want only one of each "A" item and it is possible I guess for the "A" item to be referenced twice (?) then I would be inclined to do two queries and combine the results and then potentially filter the results to make sure that the end list only contains one of each "A" item.
Another way of achieving the same thing would be to write an SQL query since it is possible to process the results inside the database and then return only the set that you are looking for.
Hope this helps.
Brian.