Is there a ORM library on Android allowing inserting POJO containing foreign field/collection? Because those I found (ORMLite for Android) usually works like that:
- Insert parent
- Link a child field to the parent object
- Insert the children
- Update the parent to make him include those foreign field
I found my code ugly having to seek for all the inner child. I would like to only have to insert the parent and then the child would be added automatically, is that even possible?
This is what I do now to insert parent full of foreign field not yet inserted:
CategoriesDAO.getInstance().addOrUpdate(categories);
for (EntityCategories.EntityCategory currentCategory : new ArrayList<>(categories.getCategories())) {
if (currentCategory.getmPlans() != null) {
for (EntityPlan myPlan : new ArrayList<>(currentCategory.getmPlans())) {
EntityPlan oldPlan = PlanDAO.getInstance().queryById(String.valueOf(myPlan.getmId()));
myPlan.setCategories(currentCategory);
if (oldPlan != null) {
if (!myPlan.getmDateModification().equals(oldPlan.getmDateModification())) {
PlanDAO.getInstance().addOrUpdate(myPlan);
}
} else {
PlanDAO.getInstance().addOrUpdate(myPlan);
}
}
} else {
continue;
}
LabelDAO.getInstance().addOrUpdate(currentCategory.getmLabel());
currentCategory.setCategories(categories);
CategoryDAO.getInstance().addOrUpdate(currentCategory);
}