fix:optimize portfolio_users query

This commit is contained in:
hackerESQ
2024-10-25 22:06:46 -05:00
parent 89c1892013
commit 57495d36d8
3 changed files with 16 additions and 6 deletions
+6 -1
View File
@@ -107,7 +107,12 @@ class Portfolio extends Model
public function getOwnerAttribute()
{
return $this->users()->firstWhere('owner', 1);
if (!$this->relationLoaded('user')) {
$this->load('users');
}
return $this->users->where('pivot.owner', true)->first();
}
public static function ensurePortfolioHasOwner(self $portfolio)