Eager load relations to determine
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user