Version 20 (modified by 15 years ago) (diff) | ,
---|
Table of Contents
Generating MOLGENIS from scratch
We will generate a new MOLGENIS by the example of a simple Address Book application:
a simple database having “Contacts” entities that each can have zero or more “Addresses”:
1. Create the data model XML
Create a new xml file ‘addressbook_db.xml’ in the root of you application. This file will contain the MOLGENIS model. Use the following template:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE molgenis PUBLIC "MOLGENIS 1.0" "http://molgenis.sourceforge.net/dtd/molgenis_v_1_0.dtd"> <molgenis name="addressbook"> </molgenis>
2. Add a “Contact” data type.
<molgenis name="addressbook"> <entity name="Contact"> </entity> </molgenis>
3. Add properties to the “Contact” data type.
- A unique, automatic numeric identifier field that MOLGENIS will use to refer contacts.
<field name="contact_id" type="autoid"/>
- A required and unique string field ‘displayname’ to have a unique label to find Contacts by. Note that if you provide no ‘type’ then type=”string” is implied.
<field name="displayname" unique="true"/>
- Optional (‘nillable’) string fields for firstname, lastname and midinitials:
<field name="firstname" nillable="true"/> <field name="midinitials" nillable="true"/> <field name="lastname" nillable="true"/>
- An optional field of type date for birthday:
<field name="birthday" type="date" nillable="true"/>
4. Similarly create a “Address” data type (to keep it simple we only do phone numbers):
- Entity address
!xml <entity name="Address">
- A unique, automatic numeric identifier field that MOLGENIS will use to refer addresses.
!xml <field name="address_id" type="autoid"/>
- Add the phone number field:
<field name="phone"/>
- Add a field where the user can choose from an enumeration of options whether the address is ‘home’,’work’,or ‘mobile’:
<field name="address_type" type="enum" enum_options="[home,work,mobile]"/>
5. Finally we need to link the Addresses to each Contact.
- In the Address entity create a ForeignKey reference to Contact
<field name="contact" type="xref" xref_field="Contact.contact_id" xref_label="displayname"/> </entity>
Note that the xref_field refers to unique field ‘contact_id’ in entity ‘Contact’. The xref_label attribute indicates that we want to view references to Contact by ‘displayname’ name instead of the numeric id.
Use of a meaningless numeric ‘id’ next to a meaningful ‘label’ enables us to change the ‘displayname’ name on Contact without the problem of also having to change this on each Address that refers to this contact.
Attachments (1)
- address-book-screenshot.JPG (40.5 KB) - added by 15 years ago.
Download all attachments as: .zip