Attributes and Domains are key for modeling.
Create a Transaction object called “Attraction”.
For each tourist attraction, the following information is requested:
- Its name
- The country where it is located
- A photo
- and a category that describes if it is a monument, a museum, a show, and so on.
The key attribute of this Transaction will be called “AttractionId”. Remember to always type a dot, so that GeneXus suggests a prefix to avoid typing mistakes.
Complete the key attribute name and set its type as numeric of 4 digits, just like you did with the Customer identifier (CustomerId).
It would be a good idea to create a common data type for all identifiers, as you will probably need to create more of them. For instance, a type called "Id" and is a numeric value of 4 digits.
This data type created is called Domain.
For example, once the Id domain is created, several attributes can be set to Id type, and they will all be 4-digit numeric values.
One advantage it provides is that, if later on, you need identifiers to be “Numeric” of length 6 instead of “Numeric” of 4, changing the “Domain” definition will be enough to update all the attributes based on that “Domain” in a single step.
To create it, press the Tab key and in the Type, column write: Id=N (it is autocompleted with Numeric):
As of now, leave the 4-digit value suggested by default.
After pressing Enter, you will see that the AttractionId attribute has now been set as Id type.
Take a look at the properties of the AttractionId attribute.
If you are positioned on the AttractionId attribute and press F4, this window will display several settings made for this attribute and will allow you to change them.
You can see that it is "Based on" the Id domain and for this reason, it is a 4-digit numeric value.
Note that properties can be sorted alphabetically
Here, the Autonumber property can be seen. This property is set to False by default and if you change it to True, all the new attractions entered will be automatically numbered in sequence.
That is to say, every time that a new attraction is added, the AttractionId attribute will be automatically assigned a new number that's bigger than the last existing number.
So, you're setting the Autonumber property specifically for this AttractionId identifier attribute.
Another option could be to set the same property for the Id domain that you've created,
so that when you create more Transaction identifier attributes, the Id domain can be assigned. In this way, they would inherit all the domain definitions (such as the data type and all the properties configured).
To see the domains created, edit the Domains window: View > Domains
Here you can create and edit domains, in a similar way to how attributes are created.
Click on the Id domain and the properties window is refreshed to show this domain’s properties.
Here you can see again the Properties categorized view instead of the alphabetical view:
Find the Autonumber property and set it to True, this will cause all Id type attributes to be automatically autonumbered in sequence.
Go back to the structure window of the Attraction Transaction and start to create its second attribute. Add the AttractionName attribute. Also, create the Name domain of Character type, length 50.
Set the Name type for the AttractionName attribute.
Now you need an attribute to record the country of the tourist attraction.
An attribute called AttractionCountry of Character(50) data type could be created and enter the country name when adding details.
What happens if you want to enter two tourist attractions from the same country?
You should enter the same country name twice, and be careful to type it exactly the same! Later on, you might need to search for all the attractions in a certain country, and to get them, the country must have been typed the same every time.
Take a look at this case:
Suppose that you’ve entered several attractions with their corresponding countries.
For example, you have an attraction with identifier 1, called Louvre, located in France, an attraction with identifier 2, called the Great Wall and located in China…and another attraction with Id=3, the Eiffel Tower, which is also in France.
You know that the Louvre is located in France and that the Eiffel Tower is also in France, but due to a typing or spelling mistake, the country name is typed differently.
Here, France is typed with two Ns. So, for the system, this country is not the same as this other one.
For this reason, this solution can't be used.
It seems more reasonable to enter the country only once, in a single location, and then make reference to the corresponding country for each attraction.
That is to say, you should define something like this:
One location where countries are stored, and in attractions you make reference to the corresponding country identifiers.
The Louvre is in France: Country 2.
The Great Wall is in China: 3.
And the Eiffel Tower is in France, also 2.
To do this in GeneXus, create a Transaction object to record the countries, and then you will see how to assign a country to each Transaction.
Meanwhile, save the Attraction structure that hasn't been completed.