( Context context, Object field )
| 616 | } |
| 617 | |
| 618 | @SuppressWarnings("unchecked") |
| 619 | private <O extends Model, T extends Model> void saveO2MToDatabase( |
| 620 | |
| 621 | Context context, |
| 622 | Object field |
| 623 | |
| 624 | ) throws NoSuchFieldException { |
| 625 | |
| 626 | OneToManyField<T, ?> om = (OneToManyField<T, ?>) field; |
| 627 | List<? extends Model> targets = om.getCachedValues(); |
| 628 | |
| 629 | for(Model target: targets) { |
| 630 | /* |
| 631 | * Only save the target, if it has already been saved once to the database. |
| 632 | * Otherwise we could save objects, that shouldn't be saved. |
| 633 | */ |
| 634 | if(target.getId() != 0) { |
| 635 | setBackLink((T) this, (Class<T>) getClass(), (O) target, (Class<O>) target.getClass()); |
| 636 | target.save(context); |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Override this method in order to roll-out migrations |
no test coverage detected