This tutorial will introduce you to what is required in order to build a relational form given some suitable data sources. A relational form contains at least two entities (but usually many more) in a parent-child relationship. The parent entity is normally a structures table of molecules with an associated primary key field defined. The child table might be any source where by there are multiple data points for each primary key entry (or molecule). The child table must contain a field which acts as foreign key, or reference to it's parent primary key. In this way, it is possible to build a simple form in Instant JChem around this simple relational data model. In this tutorial we use some small portion of ChemBl data to show the functionality. We also use the local derby database for the purposes of demonstration, the Oracle / MySQL approaches are essentially similar using the Instant JChem interface.
Establish a foreign key between entities
Next, we need to create a relationship between the two entities, that is based upon the "molregno" field which exists in both entities. These fields do not have to be named the same but the reference key must contain values that are found in the primary key. Right click on either entity and select New relationship.... In the dialog, select:
Relationship Type: New Many-to-One Relationship
Name: generated value is usually sufficient and reflects references
From: Activities; Field: molregno - This is the many child data points
To: Structures; Field: molregno - This is the parent molecule
select checkbox next to the Activities datatree - this will promote the relationship
You can see your new relationship in the schema editor, under relationships, for both entities.
You can now see your data tree has changed somewhat. You can see the root node now indicates it has dependents and you can see the child table lower in the hierarchy denoted 1:n to indicate the relationship type. If you look in entities you will see Activities is no longer greyed out - it is actively part of the data tree 'Structures'.
Create a new form view for the Data tree
From the projects editor window, right click on the data tree node and select New view.... You can choose an Empty form view and name it accordingly. If you select a Grid view you will find it displays all the fields in the root node. Next, drag a Molecule pane widget on the form. It will bind automatically to the Structures field in the Structures entity. Next, choose other fields from this entity to bind, like formula and molecular weight, a Single line text field widget is ideal for these. We can now add our child data to a form. Due to the nature of the relationship, a table widget lends itself perfectly for this task. Select a Table widget and bind it to the entity Activities (you could choose specific fields by expanding). Select Browse mode and admire the beauty of your new relational form!
Congratulations! You have just created a simple relational form by learning :
How to create project & schema
How to create data tree (Structures) and add to it a child entity (Activities)
How to create a foreign key using a relationship and edge
How to create a new relational form view and bind entities and fields