In my module, I currently have 2 entities: Main and Sub. The Sub entity is using Main.Id as its Identifier Attributes, which means Sub.Id = Main.Id . This tight coupling has worked so far, but now we have a new entity called NewMain, which is more widely used and preferred version of Main.
I want to decouple Sub from Main and Instead have it use NewMain.Id as its identifier (or at least reference).
I followed a forum suggestion to:
However, this doesn't fully work because not all MainId values exists in NewMain, so the mapping fails in some cases.
My questions are:
Should I manually map MainId to NewMainId, and accept nulls where there is no match?
Is there a better approach to migrate this relationship cleanly without losing data or creating inconsistencies?
Any best practices or OutSystems-safe approaches are appreciated.
Hello Hazrel,
Hope you're doing well.
Responding to your questions (and starting from the second one):
I would like to suggest the usage of a mapping entity with 2 attributes: MainId and NewMainId. In this mapping entity, you will have the relation between a MainId and a NewMainId, meaning a MainId corresponds to a certain NewMainId. This is usually a good approach in these scenarios, and then you can use an SQL script or a timer to populate the new attribute using this mapping entity.
Regarding first question, ideally each MainId should have a match with a NewMainId, otherwise you'll have inconsistencies. And it's hard to say if you should (or not) accept nulls without any extra info. Is your application ready to work around and handle these null values? Will they impact your app? Is this a business app / process that is going to be affected?
In the end of the day, only you (and eventually your business team) can tell if you should accept nulls or not, because they may affect your app.
In my opinion, you shouldn't: either you have a match for a NewMainId or you populate those unmatched records with another value (for example, a default value).
Hope that this helps you!
Kind regards,
Rui Barradas