Merge branch '40-on-delete-set-null-must-be-set-in-sql-schema' into 'dev'

delete cascade no more

Closes #40

See merge request sa4-2020/the-sanmarinoes/backend!54
This commit is contained in:
Matteo Omenetti 2020-03-23 17:57:23 +01:00
commit 9ed2c66b54

View file

@ -6,6 +6,7 @@ import javax.persistence.Entity;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.PreRemove;
/** Represents a generic dimmer input device */ /** Represents a generic dimmer input device */
@Entity @Entity
@ -32,4 +33,11 @@ public abstract class Dimmer extends InputDevice {
public void addDimmableLight(DimmableLight dimmableLight) { public void addDimmableLight(DimmableLight dimmableLight) {
lights.add(dimmableLight); lights.add(dimmableLight);
} }
@PreRemove
private void removeLightsFromDimmer() {
for (DimmableLight dl : getOutputs()) {
dl.setDimmerId(null);
}
}
} }