這是我的模式生成代碼:的Android GreenDAO產生額外的ID屬性
Schema schema = new Schema(VERSION, "com.example.dao");
Entity player = schema.addEntity("Player");
Property playerIdProperty = player.addStringProperty("id").primaryKey().getProperty();
player.addStringProperty("name").notNull();
player.addStringProperty("created_at");
player.addStringProperty("updated_at");
Entity match = schema.addEntity("Match");
match.addStringProperty("id").primaryKey();
match.addIntProperty("score1");
match.addIntProperty("score2");
match.addStringProperty("created_at");
match.addStringProperty("updated_at");
match.addToOne(player, playerIdProperty, "dp1");
match.addToOne(player, playerIdProperty, "dp2");
match.addToOne(player, playerIdProperty, "op1");
match.addToOne(player, playerIdProperty, "op2");
new DaoGenerator().generateAll(schema, "app/src-gen");
而這正是它產生:
public class MatchDao extends AbstractDao<Match, String> {
public static final String TABLENAME = "MATCH";
/**
* Properties of entity Match.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, String.class, "id", true, "ID");
public final static Property Score1 = new Property(1, Integer.class, "score1", false, "SCORE1");
public final static Property Score2 = new Property(2, Integer.class, "score2", false, "SCORE2");
public final static Property Created_at = new Property(3, String.class, "created_at", false, "CREATED_AT");
public final static Property Updated_at = new Property(4, String.class, "updated_at", false, "UPDATED_AT");
public final static Property Id = new Property(5, String.class, "id", true, "ID");
};
正如你所看到的,在MatchDao有兩個屬性稱爲「 ID」。我需要做的是生成主鍵爲字符串(字符串是遠程數據庫的要求)和4個外鍵(每個匹配有4個球員)的兩個表。
問題是:爲什麼「Id」屬性是重複的以及如何避免它?在此先感謝