From 6b9a1d1b74ed962986602596e96bd5d0a67328ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Falco=CC=81n?= Date: Mon, 6 Jul 2026 16:41:16 +0200 Subject: [PATCH] feat(spaces): stamp bank-synced rows and hide internal space_id Set space_id explicitly on bank-sync transaction inserts (avoids a per-row lookup during sync and anchors the row to the account's space), and hide the internal space_id foreign key from model serialization. --- app/Models/AutomationRule.php | 5 +++++ app/Models/BankingConnection.php | 1 + app/Models/Budget.php | 1 + app/Models/Label.php | 1 + app/Services/Banking/TransactionSyncService.php | 1 + app/Services/Banking/WiseTransactionSyncService.php | 1 + 6 files changed, 10 insertions(+) diff --git a/app/Models/AutomationRule.php b/app/Models/AutomationRule.php index 899a7bad..08153311 100644 --- a/app/Models/AutomationRule.php +++ b/app/Models/AutomationRule.php @@ -34,6 +34,11 @@ class AutomationRule extends Model 'action_note_iv', ]; + /** @var list */ + protected $hidden = [ + 'space_id', + ]; + protected function casts(): array { return [ diff --git a/app/Models/BankingConnection.php b/app/Models/BankingConnection.php index 26cc58b7..eea236cb 100644 --- a/app/Models/BankingConnection.php +++ b/app/Models/BankingConnection.php @@ -54,6 +54,7 @@ class BankingConnection extends Model ]; protected $hidden = [ + 'space_id', 'api_token', 'api_secret', 'pending_accounts_data', diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 6b405e50..cad0a537 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -34,6 +34,7 @@ class Budget extends Model /** @var list */ protected $hidden = [ 'period_duration', + 'space_id', ]; protected function casts(): array diff --git a/app/Models/Label.php b/app/Models/Label.php index 07ba5c45..92282596 100644 --- a/app/Models/Label.php +++ b/app/Models/Label.php @@ -31,6 +31,7 @@ class Label extends Model */ protected $hidden = [ 'pivot', + 'space_id', ]; /** @return BelongsTo */ diff --git a/app/Services/Banking/TransactionSyncService.php b/app/Services/Banking/TransactionSyncService.php index c6292ea1..71fec337 100644 --- a/app/Services/Banking/TransactionSyncService.php +++ b/app/Services/Banking/TransactionSyncService.php @@ -115,6 +115,7 @@ class TransactionSyncService try { $account->transactions()->create([ 'user_id' => $account->user_id, + 'space_id' => $account->space_id, 'description' => $formatted['description'], 'description_iv' => null, 'original_description' => $formatted['original_description'], diff --git a/app/Services/Banking/WiseTransactionSyncService.php b/app/Services/Banking/WiseTransactionSyncService.php index a04c449d..a280ccc3 100644 --- a/app/Services/Banking/WiseTransactionSyncService.php +++ b/app/Services/Banking/WiseTransactionSyncService.php @@ -166,6 +166,7 @@ class WiseTransactionSyncService try { $account->transactions()->create([ 'user_id' => $account->user_id, + 'space_id' => $account->space_id, 'description' => $parsed['description'], 'description_iv' => null, 'original_description' => $parsed['description'],