4. A SQL Query goes into a bar and
walks up to two tables and asks…
“Can I join you?”
4
5. 5
Hello!
My name is Gordon Knowitall.
I’m the boss here and I’ll be running the show!
Introductions
6. 6
Hi!
I’m NEO and I’ll be here to assist you with anything
related to the OutSystems Platform.
Introductions
7. 7
Hey! You there… Yes, I’m talking to you!
Do you even know what this company does?
6 months… and you don’t even know what we do???
Boss is in a bad mood
This is an hotel.
If you don't want to be fired, you need to create an
application for our hotel booking system.
8. 8
So, we have rooms...
And each room has a number, some have AC and we
classified them into Basic, Premium and Ultra-Mega-
Premium.
First requirements
The room number will be something like 101, 312 or 655.
9. 9
From what I’ve heard it seems that Room is a great
candidate for an entity to store the room information.
Make sure that we can get the entity attributes type from
the requirements: “some have AC” this is a good
candidate to be a Boolean.
Entities and attributes
10. 11
You know… I've been thinking…
And the room names should be different:
Silver, Gold and Diamond.
More classy…
Why doesn’t it surprise us?
11. 12
So it seems that the room type will be a list of values.
This is a good use case to use static entities.
Also, these values might change (just now our boss
changed his mind) but the room will still have the same
type independent of the name, so we can normalize here
our model.
Static Entities and Normalization
13. 15
No problem here, changing the Label won’t change
anything is the application!
Static Entities and Normalization
14. 17
Not trying to insult your intelligence…
I don't need to tell you that room numbers are unique,
right?
Obvious… but a valid one!
15. 18
This is a very valid requirement that can be enforced with
application logic but it is always a good practice to
include it in the data model. We can use the Entity Room
indexes to achieve this.
Unique Index
16. 20
Rooms have beds and we need to manage which beds
need to change mattress.
Regulation demands that a mattress needs to be
changed every 3 months.
More requirements…
17. 21
This means that a Room can have multiple beds and it is
important to keep track on the last date that the mattress
has been changed. It makes sense to have another
Entity called Bed to keep this information, linked to a
Room with a 1 to Many relationship:
1 Room can have many Bed
1 to Many
18. 23
I believe in transparency…
Let's make sure that every single room has its real photo
for our customers be able to see it.
Mr. Knowitall is the king of transparency
19. 24
To store the room picture we need to use an attribute in
the Entity of type Binary Data. This takes a lot of
information so to improve the performance, the room
picture should be in a separate entity, the Room Picture
that can have the same ID as the Room, creating a 1 to 1
relationship.
1 to 1 and Performance
20. 26
Now the easy part…
Our customers just need their name and passport and
they can book a room for a period of time.
Simple!
Easy is our middle name
21. 27
In order to achieve this, it is necessary to create another
Entity to store the Name and Passport for the Customer.
Now, this Customer needs to be linked to Room. In this
case, since many Customer can book many Room, we
need a Many to Many relationship using a third Entity that
we can call Booking.
Many to Many
22. 29
Our Booking agents reported that they are having
difficulty in seeing how many beds there are in a room.
Can you please help?
Look who’s asking gently
23. 31
Sometimes, it is better to denormalize for performance
sake. If a screen or a server action requires many
complicated logic to retrieve the data then, performance
wise it is better to denormalize the model. In this case,
the Group by isn’t that complex, but to illustrate we can
denormalize the model and add Number of Beds attribute
in Entity Room. Don’t forget to update the number when
a Bed is created or deleted.
Denormalize for performance
24. 33
Well, have I ever mentioned that we need this application
for our 2 different hotel brands?
Same application but we can't mix data!
Last but not least
25. 34
In case there is a need to have data separated for
different brands or companies it is possible to use multi-
tenancy. This won’t explain deeply how this feature
works, but gives an idea that exists and can/should be
used in this use case.
Multitenancy
26. 36
● Entities and Attributes
● Static Entities and Normalization
● Unique Index
● Relationships
● 1 to Many
● 1 to 1 and Performance
● Many to Many
● Denormalize for performance
● Multitenancy
Quick Recap
27. 37
● Data Modeling
● Data Model - Best Practices
● OutSystems Platform Best Practices
Useful links
Create Entity oom and scaffold Room to create a new Room
Naming best practices
PascalCase
Meaningfull names
Show actions
Show properties
Size (Truncate Data)
Add field has Wi-FI
Show that made an ALTER Table
Cut/Paste will lose info!
Normalization
Static
Show Data
Show ER model
New Scaffolding and create a new room.
Normalization
Static
Show Data
Show ER model
New Scaffolding and create a new room.
Indexes
Show more options
Try to create another room with the same number
Show 1 to many
Talk about delete rules
Performance
Show 1 to 1
Show many to many
Scafoold and create two customers
Create one booking
Show Group by
Denormalize for performance
Show on create/delete remove room update number of beds