{"id":2071,"date":"2021-05-03T07:51:54","date_gmt":"2021-05-03T07:51:54","guid":{"rendered":"https:\/\/sdf-docs.mansystems.com\/docs\/acr-rules\/architecture\/minimize-the-use-of-self-relations\/"},"modified":"2021-09-21T08:38:10","modified_gmt":"2021-09-21T08:38:10","slug":"architectureselfrelationsnotadviced","status":"publish","type":"docs","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/architecture\/architectureselfrelationsnotadviced","title":{"rendered":"Minimize the use of self-relations"},"content":{"rendered":"\n<p>Introduced in version 2.5 (released May 2021), extended in version 2.7 (release September 2021)<\/p>\n\n\n\n<p>Self-relations are harder to understand in the domain model and especially in xpath queries. Mendix even introduced a reversed() function to determine the direction of the xpath association to be used in a self-relation. The advice therefore is to minimize the use. And if self relations are needed, document them well, test them well and use the allow list for the violation.<\/p>\n\n\n\n<p><strong>Non-compliant examples<\/strong><\/p>\n\n\n\n<p><strong>Case 1: <\/strong>The basic self relation<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"245\" height=\"151\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-3.png\" alt=\"\" class=\"wp-image-2074\"\/><\/figure>\n\n\n\n<p><strong>Case 2: <\/strong>Child entity refering to parent it inherits from<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"230\" height=\"359\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-4.png\" alt=\"\" class=\"wp-image-2075\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-4.png 230w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-4-192x300.png 192w\" sizes=\"(max-width: 230px) 100vw, 230px\" \/><\/figure>\n\n\n\n<p><strong>Case 3: <\/strong>Rare case of a parent entity refering to a child entity<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"251\" height=\"350\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-5.png\" alt=\"\" class=\"wp-image-2076\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-5.png 251w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-5-215x300.png 215w\" sizes=\"(max-width: 251px) 100vw, 251px\" \/><\/figure>\n\n\n\n<p><strong>Compliant example<\/strong><\/p>\n\n\n\n<p>Any domain model entity not fitting in the above cases.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Configuration<\/strong><\/p>\n\n\n\n<p>This rule can check self-relations in two ways, direct and also relations to parent or child entities. The latter are sometimes wanted in complex architectures with tree-like data structures. In that case you can configure this rule or annotate to exclude violations.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"421\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/09\/c00b6125-8cd4-4dfe-ad00-fb37dded63d9-1.png\" alt=\"\" class=\"wp-image-2286\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/09\/c00b6125-8cd4-4dfe-ad00-fb37dded63d9-1.png 796w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/09\/c00b6125-8cd4-4dfe-ad00-fb37dded63d9-1-480x254.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 796px, 100vw\" \/><\/figure>\n","protected":false},"featured_media":0,"parent":99,"menu_order":14,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-2071","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2071"}],"collection":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2071"}],"version-history":[{"count":3,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2071\/revisions"}],"predecessor-version":[{"id":2288,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2071\/revisions\/2288"}],"up":[{"embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/99"}],"prev":[{"title":"Microflows should only rarely call microflows from other modules","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/architecture\/logicencapsulation","href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/275"}],"wp:attachment":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2071"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=2071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}