Skip to content

A free open source IT asset/license management system

Fix to bad relation definition in Location. (#4306)

Brady Wetheringtonad32bae62f8d
diff --git a/app/Models/Location.php b/app/Models/Location.php
index c524c1eb30..3275c296d4 100755
--- a/app/Models/Location.php
+++ b/app/Models/Location.php
@@ -59,7 +59,18 @@ class Location extends SnipeModel
public function locationAssets()
{
- return $this->hasMany('\App\Models\Asset', 'rtd_location_id')->orHas('assignedAssets');
+ /* This used to have an ...->orHas() clause that referred to
+ assignedAssets, and that was probably incorrect, as well as
+ definitely was setting fire to the query-planner. So don't do that.
+
+ It is arguable that we should have a '...->whereNull('assigned_to')
+ bit in there, but that isn't always correct either (in the case
+ where a user has no location, for example).
+
+ In all likelyhood, we need to denorm an "effective_location" column
+ into Assets to make this slightly less miserable.
+ */
+ return $this->hasMany('\App\Models\Asset', 'rtd_location_id');
}
public function parent()