2016-11-13 54 views
1

我写了一个代码来创建一些表由阿帕奇元模型:阿帕奇元模型如何添加外键在创建表

dataContext.executeUpdate(new UpdateScript() { 
     @Override 
     public void run(UpdateCallback updateCallback) { 
      updateCallback.createTable(schema, "aTable").withColumn("id").ofType(ColumnType.INTEGER) 
      .withColumn("anotherTableId").ofType(ColumnType.INTEGER).execute(); 
      updateCallback.createTable(schema, "anotherTable").withColumn("id").ofType(ColumnType.INTEGER).execute(); 
     } 
} 

如何添加这些表之间的关系?

回答

0

你可以尝试:

dataContext.executeUpdate(new UpdateScript() { 
     @Override 
     public void run(UpdateCallback updateCallback) { 
      Table aTable = updateCallback.createTable(schema, "aTable") 
       .withColumn("id").ofType(ColumnType.INTEGER) 
       .withColumn("anotherTableId").ofType(ColumnType.INTEGER).execute(); 
      Table anotherTable = updateCallback.createTable(schema, "anotherTable") 
       .withColumn("id").ofType(ColumnType.INTEGER).execute(); 

      MutableRelationship.createRelationship(
       anotherTable.getColumnByName("id"), 
       aTable.getColumnByName("anotherTableId")); 
     } 
} 
+0

不幸MutableRelationship.craeteRelationship()只更新了元不是后端数据库。 –