Model and Query Data
Use Entities to Model Data
This lesson is part of the Developer Online Class for OutSystems 9 course.
LEARN MORE

Transcript
in this lesson will seen detail how you can define your database model
in the OutSystems Platform. We will create an application that manages
Purchase Orders
let's go ahead and create the application
let's call it 'Orders' and let me give it
and icon. You can download this
icon from the resources of the video
and click Save and let's create the module for our application
okay let's start by
defining the and that these in our application and we will start with
a Client Entity and
we're going to add a few attributes to this entity and let's say we have
a Name for the client we have
Address and
Email and also
PhoneNumber. Okay
as we've discussed in previous lessons this Entity
when publish the application this entity
will map to a table in the database and the
Entity Attributes will map to columns on that table
in the database now let me just go over here the attributes that we created
and set the Name as
Mandatory, this property here that 'Is Mandatory'
this one is mandatory, the Address I'm also going to set as mandatory
and also the email and
this property this is basically metadata
that is used by the platform for input field validation
we will see further ahead how to validate inputs
but what I want to make clear is that a database constrain
is not created for mandatory attributes. Let me also do
one other thing which is quickly go over the data type
all the attributes that we created, so on a Name
is by default a Text with 50 characters long
an Address is also a Text with 50 characters, by the way let me just
change this because I I think that will need more
space to write down the address of the client and make it
100 characters long and email
is also a text, well it's not, it's an email period
let me just go ahead and press F1
here on the data type field, so this is the Entity Attribute
properties page
and here on the data type you see that we have a link to learn more about the
types
of the Entity Attributes. And in this gives you basically
all the data types that you can define in your development environment
and the mapping to the
several databases that you can use on OutSystems Platform, so for instance
in SQL Server that email is going to be a VarChar
250 characters and also
on MySQL and on Oracle you have the
the mappings here. Okay
we added these attributes to the Client Entity, but we already had here
the Id attribute
when you create an Entity an Id attribute created by default
which is an integer and an auto-number
when we create clients this identifier is going to be
automatically incremented and and this is what is called usually as a
Primary Key
it allows you to uniquely identify a record
in the Entity, in this case identify a specific Client
in OutSysytems a Primary Key is also known
as an identifier. Okay so let's create another Entity
and let's call it Product
and also let me add a few attributes to the product
Like a Name, Description
products also have
a Price and you noticed that
once I created the attribute Price the platform guessed
that this is a currency data type. So the platform tries to get
the datatypes based on the name of the attribute that to give
to those attribute and let me add
one final attribute which is the quantity in stock
and you'll notice that quantity in stock is
cleverly guesses as an integer. Let me also set a couple of this attributes as
mandatory so the
product Name is mandatory and the product Price
is also mandatory now before we continue
I want to make sure that I have some data on these Entities
so as he did before we're going to bootstrap data for
both of these Entities, let's start with the Client and
we're going to right-click here select from the Advanced menu
'Create Action to Bootstrap Data from Excel'
select the clients Excel. The mapping of the Excel column
to the Client attributes is all Ok
and let's proceed
and let's do the same for the Product
okay we're all done before we move into next lesson
let's publish so that this data from the Excel file is bootstrapped
in these Entiities in the database
that's it