Facing Issue creating ToMany Relation.

26 views
Skip to first unread message

Rahul Uppalwar

unread,
Sep 21, 2015, 3:15:47 PM9/21/15
to greenDAO
Here is the generator code. I am having 2 entities:
  1. User Entity
  2. Vendor Entity
Now one user can have many vendor, so I wanted to add usr_id from user table to vendor table. Can someone please tell me what am I doing wrong?





Schema schema = new Schema(1, "com.rgu5android.greendao.demo.model");

Entity tableUserEntity = schema.addEntity("TableUser");
tableUserEntity.addIdProperty().autoincrement();
tableUserEntity.addIntProperty("usr_id").primaryKey().notNull().unique();
tableUserEntity.addStringProperty("usr_email");
tableUserEntity.addStringProperty("usr_pwd");
tableUserEntity.addIntProperty("usr_status");
tableUserEntity.addStringProperty("usr_mobile");
tableUserEntity.addStringProperty("usr_mobile_alt");
tableUserEntity.addStringProperty("usr_city");
tableUserEntity.addIntProperty("usr_gender");
tableUserEntity.addStringProperty("usr_full_name");
tableUserEntity.addStringProperty("usr_area_name");
tableUserEntity.addStringProperty("usr_address");

Entity tableVendor = schema.addEntity("TableVendor");
tableVendor.addIdProperty().autoincrement();
tableVendor.addIntProperty("vndr_id").primaryKey().notNull().unique();
tableVendor.addStringProperty("vndr_park_name");
tableVendor.addStringProperty("vndr_park_address");
tableVendor.addStringProperty("vndr_park_area_name");
tableVendor.addStringProperty("vndr_gps_lat");
tableVendor.addStringProperty("vndr_gps_long");
tableVendor.addIntProperty("vndr_security_guard_status");
tableVendor.addStringProperty("vndr_security_mobile_number");
tableVendor.addLongProperty("vndr_timestamp");
tableVendor.addStringProperty("vndr_pincode");
tableVendor.addStringProperty("vndr_park_type_name");

Property vndr_usr_id = tableVendor.addIntProperty("usr_id").notNull().getProperty();
ToMany usr_to_vendor = tableUserEntity.addToMany(tableVendor, vndr_usr_id);
usr_to_vendor.setName("vndr_usr_id");

try {
new DaoGenerator().generateAll(schema, ".");
} catch (Exception e) {
e.printStackTrace();
}
Reply all
Reply to author
Forward
0 new messages