Non-persistent self-reference - How to find the childs for a parent?

0
Hi, Here is my problem – hope it is just ignorance, that is solvable … at least temporarily. PartCategoryNP has a parent-child relation with itself. Is it possible to find the childs via this relationship? As these are non-persistent entities, I'm not able to use a [reversed]. To solve it, I associated every PartCategoryNP with Binder via the _All association and filter those on the parent object. Workable but it does not  look like the best solution. Thanks for reading! Toon
asked
1 answers
0

Although the answer comes 2 years too late, maybe it helps someone else still.

 

You can achieve this by a Java action. Something like this:

 

/**
 * Provides the list of part category NPs subordinated to a category.
 * 
 * @param category
 *            Category whose sub-categrories shall be determined.
 * 
 * @return List of subordinated categories.
 */
private List<PartCategoryNP> getSubCategories(PartCategoryNP category)
{
    final boolean reverseRetrieve = true;
    List<IMendixObject> genericSubCategories = Core.retrieveByPath(getContext(), 
        category.getMendixObject(),
        home.proxies.PartCategoryNP.MemberNames.PartCategoryNP_PartCategoryNP
        .toString(), reverseRetrieve);

    List<PartCategoryNP> subCategories = 
        java.util.Optional.ofNullable(genericSubCategories)
        .orElse(java.util.Collections.emptyList()).stream().map(_subCategory -> 
        home.proxies.PartCategoryNP.initialize(getContext(), _subCategory))
        .collect(java.util.stream.Collectors.toList());

    return subCategories;
}

 

answered