aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-24 01:34:07 +0300
committermrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-24 01:34:07 +0300
commiteaba5c9ae0296206f8f7eeddc388519ab8ae684a (patch)
treebb1a380054b499284595913d1e19e48ef846629e
parent610aacf4a2b230f26a780c289131d6a2198957db (diff)
feat(db/models): add contact wrapper method for partner
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Partner.java12
1 files changed, 11 insertions, 1 deletions
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<PartnerContact> contacts;
+
+ public void addContact(PartnerContact contact) {
+ if (contacts == null) {
+ contacts = new HashSet<>();
+ }
+
+ contacts.add(contact);
+ contact.setPartner(this);
+ }
}