Saving nested foreign objects with ORMLite on Android

后端 未结 4 1453
-上瘾入骨i
-上瘾入骨i 2020-12-07 12:57

When working on Android, does ORMLite only save shallow level objects? I have a data structure with nested Objects, both of which are newly created, and I would like to be a

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 13:28

    @DatabaseField(foreign = true,foreignAutoCreate = true,foreignAutoRefresh = true)
    public Child child;
    

    Some Notes on this solution

    1. (foreignAutoCreate = true) work only if the ID field is not set (null or 0) according to ORMlite documentation http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html

      • foreignAutoCreate : "Set this to be true (default false) to have the foreign field will be automagically created using its internal DAO if the ID field is not set (null or 0)."
    2. This only works if generatedId is also set to true for the child table according to ORMlite documentation.

提交回复
热议问题