jaguar_orm icon indicating copy to clipboard operation
jaguar_orm copied to clipboard

hasMany update should insert if not exist object

Open hjJunior opened this issue 5 years ago • 0 comments

I have Order connected by HasMany relation with OrderItem, the insert method looks pretty good, but about update, I think its missing to create item if not exists

Imagine I created a new Order using insert with two OrderItem, so If I remove one OrderItem or maybe insert a new it won't be updated table OrderItem

    if (cascade) {
      Order newModel;
      if (model.orderProducts != null) {
        for (final child in model.orderProducts) {
          await productBean.update(child,
              cascade: cascade, associate: associate);
        }
      }
      if (model.orderItems != null) {
        if (associate) {
          newModel ??= await find(model.id);
          model.orderItems
              .forEach((x) => orderItemBean.associateOrder(x, newModel));
        }
        for (final child in model.orderItems) {
          await orderItemBean.update(child,
              cascade: cascade, associate: associate);
        }
      }
    }

hjJunior avatar Jan 30 '19 13:01 hjJunior