database - Android GreenDAO generates additional ID property -
this schema generation code:
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"); and generates:
public class matchdao extends abstractdao<match, string> { public static final string tablename = "match"; /** * properties of entity match.<br/> * can used querybuilder , 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"); }; as can see, in matchdao there 2 properties called "id". need generate 2 tables primary keys beingness strings (string remote db's requirement) , 4 foreign keys (each match has 4 players).
the question is: why "id" property duplicated , how avoid it? in advance
i made same error before. doing following:
entity player = schema.addentity("player"); property playeridproperty = player.addstringproperty("id").primarykey().getproperty(); ... match.addtoone(player, playeridproperty, "dp1"); but have add together playerid property target class:
entity player = schema.addentity("player"); player.addstringproperty("id").primarykey(); ... entity match = schema.addentity("match"); property player1idproperty = match.addlongproperty("dp1").getproperty(); ... match.addtoone(player, player1idproperty); hope helps!
android database sqlite greendao
No comments:
Post a Comment