jeudi 24 mars 2016

Combining Retrofit 2 with Greendao entities

For nested json objects like

{"members":[
            {"id":366,
             "code":"T1234",
             "defaultAddress": {
                   "addressLine1": "A2 Rityayan co-operative Housing Society"
                   "addressLine2": "P-34 Moti jheel avenue Dumdum"

               }
             }]
}

I have made the following entities in Greendao,

private static void addMember(Schema schema) {
        Entity member = schema.addEntity("CareMember");

        Property memberId = member.addLongProperty("id").primaryKey().getProperty();
member.addStringProperty("code").unique();

Entity defaultAddress = schema.addEntity("DefaultAddress");
        defaultAddress.addIdProperty();
        defaultAddress.addStringProperty("addressLine1");
        defaultAddress.addStringProperty("addressLine2");
        member.addToOne(defaultAddress, memberId);
        defaultAddress.implementsSerializable();      
}

I want to create a one to one relationship and save the models in database Although the member is saved, it is difficult to save the default address and recover it. I have devised some workaround but hope there is a proper way for this. Any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire