/ Development  

See how easily you can make entity relations

Hi there AppWorks fans,

Welcome to a new installment of AppWorks tips.

This time we take a closer look to the relation part of entity modeling. Every entity can be an instance on its own but will sometimes also have a relation with another entity. Because they belong to each other or are related to each other. All kind of relations can be created and the several option will be described in the post.


Let get right into it…

Let’s start from the previous post where we already created 2 entities. The ‘Project’ and the ‘ToDo’ entity. They live on their own at the moment, but would normally have a relation to each other as a project without anything to do is not really a project and ‘ToDo’ items not connected to a project might be a bit hard to track, but as always…This depends on the use-case that you work on. In our case we’ll make sure they are tightly connected to each other. So, the project has a ‘0 to N‘ relation to the ‘ToDo’ item and the ‘ToDo’ item has a ‘1 to 1‘ relation to the project. This way the ‘ToDo’ item can always be removed from the project, but the project can’t be removed when there are related ‘ToDo’ items.

Now for the practical low-coding part…Open the AppWorks URL and enter the low-code platform with the ‘awdev’ developer account.

Open the ‘AppWorks Development Workspace’, then open the created project and open the ‘entities’ folder. And then, my fans, open your previously crafted ‘ToDo’ entity.

Check the list of building blocks on the left and click the ‘plus’ sign after the ‘Relationship’. Now fill in the screen like this.

relation_001

The ‘ToDo’ item relates to one ‘project’ with a Label ‘To One Project’. It is always good to make use of a naming convention like we show you in this screenshot. You will benefit from it on other screens in the future.

To make the relation more tightly we’ll could mark that it’s a bidirectional relation. This forces us to also tell the project entity to make a relation to the ‘ToDo’ entity. Only you’ll get a message at this moment that you can’t make it bidirectional as the project entity is not yet related to the ‘ToDo’ entity. So, we’ll make it bidirectional from the project entity perspective.

Hit the ‘Add’ button, save the ‘ToDo’ entity and close the panel.

Now we’ll do the same for the project entity. Open it up and hit the ‘plus’ sign behind the ‘Relationships’ building block. Fill in the form like this:

relation_002

Make sure to use the proper labels. Make this one a ‘relates to many’ relation as a project can have multiple ‘ToDo’ items. You should be able to also make it bidirectional with the ‘ToOneProject’ relations just created. When you model this on paper it will look like this.

relation_003

Click that ‘Add’ button. Save the entity and close the panel.

Next step is to decide what should happen when any of the related entity instances are removed from the system. In our case we’ll make sure that ‘ToDo’ items can always be deleted, but a project can’t be deleted when it’s referenced by a ‘ToDo’ item.

For this low-code part we need to open the ‘ToDo’ entity where we can click on the just created relation ‘ToOneProject’. In the right panel you see some information about the relationship and an ‘advanced configuration’ panel. Unmark the option ‘Allow users to delete a project if referenced by a ToDo‘.

relation_004

Save the entity and close the panel.

The relation option that is not covered in this post is the ‘has a child‘ relation. This can be used in our case when we start introducing tasks that are connected to our ‘ToDo’ item. These tasks belong to the ‘ToDo’ item and can also be removed when the task is removed. See it like a ‘repeating’ property on the task. A ‘repeated’ valued property is not an option to choose when you add new properties to an entity!


And that again gives us a nice ‘DONE’ for creating our first relations to the already created entities. Let me know what you think in the comments and then I will see you in our next post where we’ll do a background check on the file-store when we ‘synch’ our project!

Don’t forget to subscribe to get updates on the activities happening on this site.