From 4108868b19cea03f121037fd6468af528d5a2032 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 30 Oct 2022 20:48:43 +1100 Subject: [PATCH] don't link entities when we are in a transaction --- app/Repositories/BaseRepository.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 1595b422eda5..127387abbfff 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -304,8 +304,9 @@ class BaseRepository if (! $model->design_id) $model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id')); - //links tasks and expenses back to the invoice. - $model->service()->linkEntities()->save(); + //links tasks and expenses back to the invoice, but only if we are not in the middle of a transaction. + if (\DB::transactionLevel() == 0) + $model->service()->linkEntities()->save(); if($this->new_model) event('eloquent.created: App\Models\Invoice', $model);