Outsystems offline data synchronisation Read/Write Data One-to-Many


I have a question about the following read/write data one-to-many pattern:


In the example from Outsystems there are 2 entities: 'Company' and 'Contact'. The 'Contact' entity holds the primary ID of the Company entity.

What happends in this scenario when there are Contact records in the server database. But in the offline datamodel the user decided to remove the Company. (The Company is than set to IsActive = False in the local database,) so it will be deleted upon the next sync. This means that all the Contact records associated with the Company should also be removed.

What is the best way (best practice) to tackle this problem in the current read/write one-to-many pattern? Since I believe the current pattern doesn't support this scenario. Since first the Company entity is synced with the server. This means the Company record will be deleted from the server, since IsActive is set to 'false'. However the server will return an error that there are still Contact Records associated with the primary ID of the Company and that it's therefore not possible to delete the mentioned CompanyRecord. 

Any help would be greatly appreciated!

Kind regards,

Bash Nie


I think here OutSystems entity delete rules comes into the action. If we set delete rule to "Delete" then if a company is get deleted then related contacts will also be deleted on server as well as in local database.

If this is the case of soft delete in which we only marking it as inActive false, then need to write logic manually that if a company is Inactive then related Contacts should be delete or mark as inactive.



Delete rule does not apply in local storage if I remember correctly.

Decided to go with the following solution.

When a company is deleted locally. Now all (related) contact records are deleted from the offline data model, even if they are from the server. (before those where set on 'IsActive = False)'. This way during the sync. Those contact records are not fetched anymore from the offline datamodel, since they don't exists. This is good. Because we don't want to sync/delete those records again during the sync of the contact entity, since they where already deleted during the sync of the company entity. 

In the sync action of the company entity we now delete related contact records of deleted companies. 


Again this answer marked as solution is not completely correct as it suggest delete rule works on local storage

Yes.  you are right. delete rule is ignore on local db and we can't control it. But on server we can control delete rules.

So if any company mark is delete true in local db then on sync it will delete the company from server. If on server delete rule is delete then all the contacts associated with the deleted company will also removed. and IsActive will be false for those contacts. When contacts get sync these contacts will be removed from local db as well.

Please correct me if am wrong or missed something.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.