aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-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);
+ }
}