From a02fbfd74cb83daa13b6994068b8684be083591a Mon Sep 17 00:00:00 2001 From: James Brooks Date: Wed, 31 Dec 2014 14:12:25 +0000 Subject: [PATCH] Only validate the component relationship if we sent one through. Closes #157 --- .../Incident/EloquentIncidentRepository.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/CachetHQ/Cachet/Repositories/Incident/EloquentIncidentRepository.php b/app/CachetHQ/Cachet/Repositories/Incident/EloquentIncidentRepository.php index 26bf1104..36216b22 100644 --- a/app/CachetHQ/Cachet/Repositories/Incident/EloquentIncidentRepository.php +++ b/app/CachetHQ/Cachet/Repositories/Incident/EloquentIncidentRepository.php @@ -18,8 +18,11 @@ class EloquentIncidentRepository extends EloquentRepository implements IncidentR { $incident = new $this->model($array); $incident->user_id = $user_id; + $this->validate($incident); - $this->validate($incident)->hasRelationship($incident, 'component'); + if (isset($array['component_id'])) { + $incident->hasRelationship($incident, 'component'); + } $incident->saveOrFail(); @@ -30,8 +33,11 @@ class EloquentIncidentRepository extends EloquentRepository implements IncidentR { $incident = $this->model->findOrFail($id); $incident->fill($array); + $this->validate($incident); - $this->validate($incident)->hasRelationship($incident, 'component'); + if (isset($array['component_id'])) { + $incident->hasRelationship($incident, 'component'); + } $incident->update($array);