From eaba5c9ae0296206f8f7eeddc388519ab8ae684a Mon Sep 17 00:00:00 2001 From: mrfoxygmfr Date: Mon, 24 Mar 2025 01:34:07 +0300 Subject: feat(db/models): add contact wrapper method for partner --- .../mrfoxygmfr/warehouse_accounting/db/models/Partner.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Partner.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Partner.java index 78f203c..ad592ae 100644 --- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Partner.java +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Partner.java @@ -3,6 +3,7 @@ package ru.mrfoxygmfr.warehouse_accounting.db.models; import jakarta.persistence.*; import lombok.*; +import java.util.HashSet; import java.util.Set; @Entity @@ -36,7 +37,16 @@ public class Partner { @NonNull private String address; - @OneToMany(mappedBy = "partner") + @OneToMany(mappedBy = "partner", cascade=CascadeType.ALL, orphanRemoval = true) @ToString.Exclude private Set contacts; + + public void addContact(PartnerContact contact) { + if (contacts == null) { + contacts = new HashSet<>(); + } + + contacts.add(contact); + contact.setPartner(this); + } } -- cgit mrf-deployment