Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasMany update should insert if not exist object #104

Open
hjJunior opened this issue Jan 30, 2019 · 0 comments
Open

hasMany update should insert if not exist object #104

hjJunior opened this issue Jan 30, 2019 · 0 comments

Comments

@hjJunior
Copy link

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);
        }
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant