One-To-Many relationship in ORMLite Android

后端 未结 3 815
滥情空心
滥情空心 2021-02-08 09:53

How do I implement one-many relationship in ORMLite Android?

please find the example

public class A {
 private String name;
    @DatabaseField (foreign =         


        
3条回答
  •  忘了有多久
    2021-02-08 10:20

    i was facing the same problem. My json was like:

    {
       "parent":{
                "name":"ABC",
                "children":[
                              {"childName":"1"},
                              {"childName":"2"},
                              {"childName":"3"}
                           ]
                 }
    }
    

    i resolved the issue like this:

    Parent parent = new Parent();
    parent.setName("ABC");
    
    while(get children one by one from json data)
    {
        childrenArray.add(new Child(its Name));
    }
    
    parentDAO.create(parent);
    
    for(Child child : childrenArray)
    {
        child.setParent(parent);
        childDAO.create(child);
    }
    

提交回复
热议问题