JDeveloper - table relations

27
JDeveloper for Joomla 3.x Table relations

Transcript of JDeveloper - table relations

Page 1: JDeveloper - table relations

JDeveloper for Joomla 3.x

Table relations

Page 2: JDeveloper - table relations

In this presentation we will learn the basics of the relational table design and how to implement it in JDeveloper.

Table relations

Page 3: JDeveloper - table relations

The relational table designThe idea of the relational table design is to connect rows of different tables by their primary keys. In our example we want to create a table for articles and one for categories. Each article belongs to a category. Ou tables will look like this: (see next page)

Page 4: JDeveloper - table relations

Our table structuretable 'articles' { int 'id' int 'category' varchar 'title' text 'article'}

table categories { int 'id' varchar 'title'}

Page 5: JDeveloper - table relations

Create category itemsNo we create two categories:

id title

1 Food critics

2 Holiday experiences

Page 6: JDeveloper - table relations

Create an articleNow we need articles. In our example we write an article about our last trip to Spain. This article belongs to the holiday-category. Instead of saving the name of the category we will save it's primary key (id) in the article table. The result will look like this (see next page):

Page 7: JDeveloper - table relations

Article table

id category title article

1 2 Holidays in Spain A few weeks ago we visited spain ...

Page 8: JDeveloper - table relations

Benefits of relational tablesThe relational table design makes it much easier to manage data. If we decide to rename a category, we only have to modify one single row in the category table, because the primary key is never modified.

Page 9: JDeveloper - table relations

Table relations in JoomlaJoomla uses the relational table design especially for connecting items with categories or with users. In many database tables you will find a column named 'catid' or 'category', which contains a primary key of a row in the category table.

Page 10: JDeveloper - table relations

You will also find tables with columns named 'created_by' and 'modified_by'. These column contain primary key of the users-table and save the information about the author of an item and about it's last modifier.

Table relations in Joomla

Page 11: JDeveloper - table relations

Table relations in Joomla

Some tables also have a column named 'assed_id'. This column is a link to the assets-table. This column contains the information about access right of items.

Page 12: JDeveloper - table relations

Table relations in JDeveloperNow we know the function of related tables. In JDeveloper we need a component with at least two tables. In our example we create a warehouse component and name it 'WarehouseManager'. Add two tables with the following structure (next site):

Page 13: JDeveloper - table relations

Table structurewarehouses { int 'id' varchar 'name' text 'address'}

goods { int 'id' varchar 'name'}

Page 14: JDeveloper - table relations

Table structure

Page 15: JDeveloper - table relations

Warehouse componentThe first table contains the information about our warehouses. The second table contains the information about the goods and in which warehouse they are stored.

Page 16: JDeveloper - table relations

Warehouse componentNow we need to tell JDeveloper that it should link the two tables. Edit the goods-table and move to the 'relations' inputbox. Select the warehouse table and click save. That's all.JDeveloper will add a column to the goods table and create a list field for the warehouses.

Page 17: JDeveloper - table relations
Page 18: JDeveloper - table relations

Relate tablesJDeveloper automatically adds the warehouse column to the table:

Page 19: JDeveloper - table relations

Add goods to warehousesNow we install the component and add two warehouses to our warehouse table:

Page 20: JDeveloper - table relations

Create goodsNow we need to add goods. In our example we add a good named ‘Red bike’ to the second warehouse. This will look like this:

Page 21: JDeveloper - table relations

Create goodsAdd ‘Red bike’ to ‘Second Warehouse’

Page 22: JDeveloper - table relations

Filter functionJDeveloper also create a filter function for table relations. You are able to filter your list by warehouses like you are able to filter lists by categories or users in other components.

Page 23: JDeveloper - table relations

Filter function

Page 24: JDeveloper - table relations

More than one relationWe could also add more than one relation to the goods table. For example we want to save information about the transport mode of goods (train, truck, car). We add a new table to our component with the following structure:

Page 25: JDeveloper - table relations

Transport mode tabletransport { int 'id' varchar 'name'}

Page 26: JDeveloper - table relations

Relate tablesNow go back to the goods table and repeat the step you've done to link the goods table with the warehouse table.

You are able to create unlimited relations to other tables.

Page 27: JDeveloper - table relations

The EndThat’s it. You are now able to create related tables with JDeveloper.