Added transactions relation for n+1 issues..

This commit is contained in:
Cüneyt Şentürk 2025-11-15 10:44:46 +00:00
parent c6716e7763
commit 7e5a64262c
2 changed files with 2 additions and 2 deletions

View File

@ -207,7 +207,7 @@ trait Documents
$today = Date::today()->toDateString();
// Eager load transactions with currency to prevent N+1 queries when calling getAmountConvertedToDefault()
$documents = $documents ?: Document::type($type)->with(['transactions.currency'])->future();
$documents = $documents ?: Document::type($type)->with(['transactions', 'transactions.currency'])->future();
$documents->each(function ($document) use (&$totals, $today) {
if (! in_array($document->status, $this->getDocumentStatusesForFuture())) {

View File

@ -37,7 +37,7 @@ class Content extends Component
$docs = $this->contact->isCustomer() ? 'invoices' : 'bills';
// Eager load transactions with currency to prevent N+1 queries when calling getAmountConvertedToDefault()
$this->documents = $this->contact->$docs()->with(['transactions.currency'])->get();
$this->documents = $this->contact->$docs()->with(['transactions', 'transactions.currency'])->get();
$this->counts['documents'] = $this->documents->count();