Eager load relations to determine

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2024-02-20 22:25:00 +00:00
parent 71610fb20f
commit 04891c7c61
2 changed files with 14 additions and 6 deletions
+8 -5
View File
@@ -95,7 +95,10 @@ class Location extends SnipeModel
/**
* Determine whether or not this location can be deleted
* Determine whether or not this location can be deleted.
*
* This method requires the eager loading of the relationships in order to determine whether
* it can be deleted. It's tempting to load those here, but that increases the query load considerably.
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v3.0]
@@ -104,10 +107,10 @@ class Location extends SnipeModel
public function isDeletable()
{
return Gate::allows('delete', $this)
&& ($this->assignedAssets()->count() === 0)
&& ($this->assets()->count() === 0)
&& ($this->children()->count() === 0)
&& ($this->users()->count() === 0);
&& ($this->assets_count === 0)
&& ($this->assigned_assets_count === 0)
&& ($this->children_count === 0)
&& ($this->users_count === 0);
}
/**