Merge branch '43-delete-cascade-in-switch' into 'dev'

delete cascade no more in switch

Closes #43

See merge request sa4-2020/the-sanmarinoes/backend!55
This commit is contained in:
Matteo Omenetti 2020-03-23 18:35:11 +01:00
commit bbfb9f8fcb

View file

@ -5,6 +5,7 @@ import java.util.Set;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.PreRemove;
/** A switch input device */ /** A switch input device */
@Entity @Entity
@ -51,4 +52,11 @@ public class Switch extends InputDevice {
public Set<Switchable> getOutputs() { public Set<Switchable> getOutputs() {
return switchables; return switchables;
} }
@PreRemove
private void removeSwitchable() {
for (Switchable s : getOutputs()) {
s.setSwitchId(null);
}
}
} }