This example maps a repository item to a primary table and a multi-value table with an array property. This demonstrates a one-to-many relationship.
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE gsa-template PUBLIC "-//Art Technology Group, Inc.//DTD Dynamo Security//EN" "http://www.atg.com/dtds/gsa/gsa_1.0.dtd"> <gsa-template> <header> <name>Repository Example Version C</name> <author>Pat Durante</author> <description> This template maps a repository item to a primary table and a multi-value table using an array property. A one-to-many relationship. The "multi" table contains a list of a user's favorite subjects (simple strings). When using an "array" property, the "multi" table requires a "multi-column-name" (e.g., seq_num) to ensure that the ordering of the multi-values are maintained. </description> </header> <item-descriptor name="user" default="true"> <table name="usr_tbl" type="primary" id-column-names="id"> <property name="id" data-type="string"/> <property name="name" column-names="nam_col" data-type="string"/> <property name="age" column-names="age_col" data-type="int"/> </table> <table name="subjects_tbl" type="multi" id-column-names="id" multi-column-name="seq_num"> <property name="favoriteSubjects" column-names="subject" data-type="array" component-data-type="string"/> </table> </item-descriptor> </gsa-template>
SQL Statements
drop table usr_tbl; drop table subjects_tbl; CREATE TABLE usr_tbl ( id VARCHAR(32) not null, nam_col VARCHAR(32) null, age_col INTEGER null, primary key(id) ); CREATE TABLE subjects_tbl ( id VARCHAR(32) not null references usr_tbl(id), seq_num INTEGER not null, subject VARCHAR(32) null, primary key(id, seq_num) );