{"id":2064,"date":"2021-05-03T05:31:52","date_gmt":"2021-05-03T05:31:52","guid":{"rendered":"https:\/\/sdf-docs.mansystems.com\/docs\/acr-rules\/architecture\/retrieve-by-association-from-persistent-to-non-persistent-is-not-adviced\/"},"modified":"2021-05-20T09:33:04","modified_gmt":"2021-05-20T09:33:04","slug":"microflowactionretrievebyassociationpersistenttononpersistent","status":"publish","type":"docs","link":"https:\/\/sdf-docs.clevr.com\/?docs=acr-rules\/architecture\/microflowactionretrievebyassociationpersistenttononpersistent","title":{"rendered":"Retrieve by association from persistent to non-persistent is not advised"},"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>Since Mendix 7 the Mendix runtime is stateless and you can run multiple instances on the same database, see scaling in the Mendix cloud for example. Non-persistent objects can be created in microflows and exist during execution in a Mendix runtime. Also the browser maintains a cache of non-persistent objects. However this browser cache is cleared when the object is no longer needed. This can be on closing a page or after some time or on switch a row in a grid. Also, when the microflow retrieves the persistent entity from the database the association from the non-persistent entity is not linked to this copy.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"223\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image.png\" alt=\"\" class=\"wp-image-2067\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image.png 595w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-480x180.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 595px, 100vw\" \/><\/figure>\n\n\n\n<p>Therefore you can use following associations in a retrieve by association:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Persistent to persistent, because data is in the database<\/li><li>Non-persistent to non-persistent, because all data is in the browser<\/li><li>Non-persistent to persistent, because your browser non-persistent refers to a database record<\/li><\/ul>\n\n\n\n<p><strong>Non-compliant examples<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"680\" height=\"220\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-1.png\" alt=\"\" class=\"wp-image-2068\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-1.png 680w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-1-480x155.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 680px, 100vw\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Compliant example<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"215\" src=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-2.png\" alt=\"\" class=\"wp-image-2069\" srcset=\"https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-2.png 678w, https:\/\/sdf-docs.clevr.com\/wp-content\/uploads\/2021\/05\/image-2-480x152.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 678px, 100vw\" \/><\/figure>\n\n\n\n<p><strong>How to solve a violation<\/strong><\/p>\n\n\n\n<p>This violation is in the architecture section, because it is harder to resolve. You can consider redesigning the page and have a container non-persistent object that keeps references to all needed non-persistent objects.<\/p>\n\n\n\n<p>In essence the best practice is that going from persistent to non-persistent should be avoided at all times. <\/p>\n","protected":false},"featured_media":0,"parent":99,"menu_order":14,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-2064","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2064"}],"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=2064"}],"version-history":[{"count":4,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2064\/revisions"}],"predecessor-version":[{"id":2127,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=\/wp\/v2\/docs\/2064\/revisions\/2127"}],"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=2064"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/sdf-docs.clevr.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=2064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}