Root Node Singleton


I'm currently trying to implement a unique constraint dependent on a particular root node concept. Let's say I have a root node concept R, I want to ensure that this concept has only one instance per model. Hence, I implemented two checks/restrictions:

  • I used a Non-Typesystem Rule for reporting an error in case of multiple instances of R. B
  • I created a concept constraint for "can be root" as follows:
    model.roots(R).size == 0

To my current understanding, the concept constraint is for restraining the auto-completion menu when creating a new node. To my surprise, the second check is also performed after node creation. Since it seems to be not possible to access the node, that is "currently in creation" I haven't found any way to condition my second rule.

Does anybody have an idea? Do I miss anything?

Thank you very much in advance,
You are right. Only the checking rule can help you here, AFAIK.

Hi Vaclav,

thank you very much for your fast reply. Using the concept constraint leads to an odd behavior, since I'm able to insert a new node of type R if none is present, yet. But afterwards the same checking mechanisms mark the inserted node as an error. Is this behavior desired?

Thanks again,
Yes, the can be root constraint is evaluated on existing nodes as well as on newly created ones.

Please sign in to leave a comment.