Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How do I create Datasource with foreign key ?

    My table as follow..
    ----------------------------------
    CREATE TABLE `argroup` (
    `ArGroupCode` varchar(15) NOT NULL DEFAULT '',
    `ArGroupDesc` varchar(100) DEFAULT NULL,
    `ArGroupMainCode` varchar(15) DEFAULT NULL,
    PRIMARY KEY (`ArGroupCode`),
    KEY `ArGroupMainCode` (`ArGroupMainCode`),
    CONSTRAINT `argroup_ibfk_1` FOREIGN KEY (`ArGroupMainCode`) REFERENCES `argroupmain` (`ArGroupMainCode`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    CREATE TABLE `argroupmain` (
    `ArGroupMainDesc` varchar(100) DEFAULT NULL,
    `ArGroupMainCode` varchar(15) NOT NULL,
    PRIMARY KEY (`ArGroupMainCode`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ------------------------------------

    Then when I create DataSource from DataSource Generator I got.
    -------------------------------
    <DataSource
    generatedBy="7.0RC/Enterprise Development Only 2009-04-21"
    serverType="sql"
    dbName="Mysql"
    dataSourceVersion="1"
    tableName="argroup"
    ID="argroup"
    >
    <fields>
    <field primaryKey="true" type="text" length="15" name="ArGroupCode"></field>
    <field type="text" length="100" name="ArGroupDesc"></field>
    <field type="text" length="15" name="ArGroupMainCode"></field>
    </fields>
    </DataSource>
    --------------------------------------
    <DataSource
    generatedBy="7.0RC/Enterprise Development Only 2009-04-21"
    serverType="sql"
    dbName="Mysql"
    dataSourceVersion="1"
    tableName="argroupmain"
    ID="argroupmain"
    >
    <fields>
    <field type="text" length="100" name="ArGroupMainDesc"></field>
    <field primaryKey="true" type="text" length="15" name="ArGroupMainCode"></field>
    </fields>
    </DataSource>
    ------------------------------------------
    Then I got only fields of it own table.
    But I want to get field which argroup has a foreign key to argroupmain

    Like this

    select argroup.argroupcode, argroup.argroupdesc, argroupmain.argroupmaindesc
    from argroup
    inner join argroupmain
    on argroup.argroupmaincode = argroupmain.argroupmaincode

    How do I create DataSource to do like this,, please ??

    Thanit

    #2
    For the current version you need to add the foreignKey declaration yourself, or, generate the tables from the DataSource definition instead using the Admin Console. That's typically a better way of doing it since the DataSource has more information than SQL Schema can express.

    Comment

    Working...
    X