Web-D-Zine( WDZ ) creates code to maintain and use in conjunction with a relational database, so an understanding or how relationships are dealt with in WDZ would be an advantage.
Stand alone
Stand alone code are pieces of code or data that can stand alone. They do not need any other piece of code or data, other than the data used to initialise them to work. In the library of WDZ, a good example of stand alone code is the calendar class, which is used to maintain and display a calendar. The information that is used to initialise the calendar, is the date, for which you are interested in. If no date is provided then today's date is used as a default. The code can them be used to show a calendar in monthly, weekly or daily form.
To make the calendar really useful however then you need to have events added like holidays, events, appointments etc. While the calendar can be stand alone, events will interact with the data base.
Parent -< Child
Within WDZ the parent child relationship is limited to a single parent who has children. Within WDZ then the form and its fields are a good example of this parent to child relationship in action. The parent is the form which has a unique code, which in this case is the form's name. This code can then be found in every single field record, so that the form can quickly collect all the form fields, the children together. The form name/field name creates a unique key so that the correct record can be retrieved. It may be that two fields have exactly the same field name, but seeing as they belong to different parents they are treated as different children.
Cross reference relationships
These are not angry relationships, but is the term used for the relationship between two parents. There is only one way to deal with these type of relationships and that is to create a table that has the two parents as keys, this will effectively create two single parent to children relationships.
Example 1
Consider the relationship between a customer and products. Customers are considered as parents as they need to track, the products they have bought as well as comments, reviews and the current status of their last order. Products are also parents as they will have stock associated to them, along with pictures and other attributes. A customer can buy a variety of products, while a product may which to know which customers bought it so that these customers can write reviews and leave comments about the product.
Breaking this relationship down then the customer can have a single parent to child relationship to shopping baskets which will have their own unique code. The shopping basket will then have a parent to child relationship to an item in the basket. It is this file that will also have a single parent to child relationship to the product along with other information like the quantity of products bought and the price of the product at that time. The item in basket table is effectively the cross reference file, as the product can find which baskets contain the product and thus the customers that bought it, while the customer can see exactly what products they purchased.
Example 2
Sometimes a relationship is needed between two similar parents. Consider products, there can be a variety of relationships between products, for example a product might well be a kit which is made up of several different products, or there may be other products that are classed as a substitute for the selected product, or it might just be that a product is repeatedly bought with other products. When connections like this are required then a file is created that will have a single parent to child relationship to the primary product, there will also be a single parent to child relationship to the secondary product. This way the primary products are linked to the secondary products as well as the secondary products being linked to the primary products. Other information like the type of relationship may well be needed to be stored in this file. In WDZ, when a parent to child relationship is specified than the option to create a cross reference to the same parent becomes available.
In both examples, once two parents are specified then the ability to create a parent to child relationship disappears.
Image by Myriams-Fotos from Pixabay