We just added a table to the database to store our categories.
We're going to apply these categories to the articles in the article table.
In a relational database there are different types of relationships between tables.
A one to one relationship is where one rijkaard from one table is related to one and only one rijkaard
from another table.
For example in our CNS any single article could only have one category.
Additionally any category could only be related to a single article.
To model this in the database we add a field to the article table kalid category idae.
This will be an integer which will default to Noel and this art somatically checks the column allowing
the field to contain a nil value will add a unique index on this column.
Let's save that.
And there is the new column.
This field is called a foreign key.
It's a field that links to a primary key field on another table from a field to be a foreign key.
It needs to have an index on it.
Next we need to define the relationship between the two tables.
Based on this field if I click relation view then we can select the category idae column we just added.
The table that were relating it to which is category and the column in that table which is the idae.
When I click save the foreign key relationship is added.
If we browse the Ricardos in the article table now and edit one of them.
We can see the values of the Ricardos columns.
The category idae is shown as a select list where we can select one of the categories from the other
table.
Select one and save the rijkaard.
This place is the I.D. of the Category rijkaard in the foreign key field of the article rijkaard.
Let's edit another one and select the same category.
When I click save we get an error.
This is because of the unique index on the category i.e. column.
This is what makes this a one to one relationship.
An article can only have one category as the category idees field can only contain one value and the
category can only be assigned once to an article because of this unique index.
This kind of relationship is not very common.
We could model the same data by simply including the name of the category is a field in the article
table.
There's not much point in having a separate category table like this for a one to one relationship.
However there are certain cases where this type of relationship is used so it's important to be aware
of it.