Compare commits
1 commit
dev
...
feat/works
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3976e52f43 |
1 changed files with 52 additions and 0 deletions
|
|
@ -54,6 +54,17 @@ class Workspace extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relationships that should be eager-loaded by default.
|
||||||
|
*
|
||||||
|
* Explicitly empty to prevent N+1 queries when listing workspaces.
|
||||||
|
* Use scopeWithCommon() to eager-load the most frequently needed
|
||||||
|
* relationships, or call ->with() explicitly for specific use cases.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $with = [];
|
||||||
|
|
||||||
protected static function newFactory(): WorkspaceFactory
|
protected static function newFactory(): WorkspaceFactory
|
||||||
{
|
{
|
||||||
return WorkspaceFactory::new();
|
return WorkspaceFactory::new();
|
||||||
|
|
@ -778,6 +789,47 @@ class Workspace extends Model
|
||||||
return $query->orderBy('sort_order');
|
return $query->orderBy('sort_order');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to eager-load the most commonly needed relationships.
|
||||||
|
*
|
||||||
|
* Use this when listing workspaces or rendering dashboards to avoid
|
||||||
|
* N+1 queries. Only loads core tenant relationships that are almost
|
||||||
|
* always needed; module-specific relationships (social, analytics,
|
||||||
|
* trust, notify, commerce, etc.) should be loaded explicitly.
|
||||||
|
*
|
||||||
|
* Example: Workspace::withCommon()->paginate(20)
|
||||||
|
*/
|
||||||
|
public function scopeWithCommon($query)
|
||||||
|
{
|
||||||
|
return $query->with([
|
||||||
|
'users',
|
||||||
|
'members',
|
||||||
|
'teams',
|
||||||
|
'workspacePackages',
|
||||||
|
'namespaces',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope to add commonly needed relationship counts.
|
||||||
|
*
|
||||||
|
* Lighter alternative to withCommon() when only counts are needed
|
||||||
|
* (e.g. admin listing pages). Uses withCount() to add _count
|
||||||
|
* columns without loading full relationship collections.
|
||||||
|
*
|
||||||
|
* Example: Workspace::withCommonCounts()->paginate(20)
|
||||||
|
*/
|
||||||
|
public function scopeWithCommonCounts($query)
|
||||||
|
{
|
||||||
|
return $query->withCount([
|
||||||
|
'users',
|
||||||
|
'members',
|
||||||
|
'teams',
|
||||||
|
'workspacePackages',
|
||||||
|
'invitations',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to array format used by WorkspaceService.
|
* Convert to array format used by WorkspaceService.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue