Skip to content

A free open source IT asset/license management system

Fixed RB-4120 - Column 'location_id' in where clause is ambiguous

snipeef746a173e8b
diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php
index 4a2bef8072..78382b5496 100644
--- a/app/Http/Controllers/Api/AccessoriesController.php
+++ b/app/Http/Controllers/Api/AccessoriesController.php
@@ -84,23 +84,23 @@ class AccessoriesController extends Controller
}
if ($request->filled('category_id')) {
- $accessories->where('category_id', '=', $request->input('category_id'));
+ $accessories->where('accessories.category_id', '=', $request->input('category_id'));
}
if ($request->filled('manufacturer_id')) {
- $accessories->where('manufacturer_id', '=', $request->input('manufacturer_id'));
+ $accessories->where('accessories.manufacturer_id', '=', $request->input('manufacturer_id'));
}
if ($request->filled('supplier_id')) {
- $accessories->where('supplier_id', '=', $request->input('supplier_id'));
+ $accessories->where('accessories.supplier_id', '=', $request->input('supplier_id'));
}
if ($request->filled('location_id')) {
- $accessories->where('location_id', '=', $request->input('location_id'));
+ $accessories->where('accessories.location_id', '=', $request->input('location_id'));
}
if ($request->filled('notes')) {
- $accessories->where('notes', '=', $request->input('notes'));
+ $accessories->where('accessories.notes', '=', $request->input('notes'));
}
// Make sure the offset and limit are actually integers and do not exceed system limits
diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.php
index 8731140c2f..f0019a2028 100644
--- a/app/Http/Controllers/Api/ComponentsController.php
+++ b/app/Http/Controllers/Api/ComponentsController.php
@@ -80,7 +80,7 @@ class ComponentsController extends Controller
}
if ($request->filled('name')) {
- $components->where('name', '=', $request->input('name'));
+ $components->where('components.name', '=', $request->input('name'));
}
if ($request->filled('company_id')) {
@@ -92,27 +92,27 @@ class ComponentsController extends Controller
}
if ($request->filled('category_id')) {
- $components->where('category_id', '=', $request->input('category_id'));
+ $components->where('components.category_id', '=', $request->input('category_id'));
}
if ($request->filled('supplier_id')) {
- $components->where('supplier_id', '=', $request->input('supplier_id'));
+ $components->where('components.supplier_id', '=', $request->input('supplier_id'));
}
if ($request->filled('manufacturer_id')) {
- $components->where('manufacturer_id', '=', $request->input('manufacturer_id'));
+ $components->where('components.manufacturer_id', '=', $request->input('manufacturer_id'));
}
if ($request->filled('model_number')) {
- $components->where('model_number', '=', $request->input('model_number'));
+ $components->where('components.model_number', '=', $request->input('model_number'));
}
if ($request->filled('location_id')) {
- $components->where('location_id', '=', $request->input('location_id'));
+ $components->where('components.location_id', '=', $request->input('location_id'));
}
if ($request->filled('notes')) {
- $components->where('notes', '=', $request->input('notes'));
+ $components->where('components.notes', '=', $request->input('notes'));
}
// Make sure the offset and limit are actually integers and do not exceed system limits
diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php
index b41b72a645..82aa1feb7f 100644
--- a/app/Http/Controllers/Api/ConsumablesController.php
+++ b/app/Http/Controllers/Api/ConsumablesController.php
@@ -67,7 +67,7 @@ class ConsumablesController extends Controller
}
if ($request->filled('name')) {
- $consumables->where('name', '=', $request->input('name'));
+ $consumables->where('consumables.name', '=', $request->input('name'));
}
if ($request->filled('company_id')) {
@@ -79,27 +79,27 @@ class ConsumablesController extends Controller
}
if ($request->filled('category_id')) {
- $consumables->where('category_id', '=', $request->input('category_id'));
+ $consumables->where('consumables.category_id', '=', $request->input('category_id'));
}
if ($request->filled('model_number')) {
- $consumables->where('model_number', '=', $request->input('model_number'));
+ $consumables->where('consumables.model_number', '=', $request->input('model_number'));
}
if ($request->filled('manufacturer_id')) {
- $consumables->where('manufacturer_id', '=', $request->input('manufacturer_id'));
+ $consumables->where('consumables.manufacturer_id', '=', $request->input('manufacturer_id'));
}
if ($request->filled('supplier_id')) {
- $consumables->where('supplier_id', '=', $request->input('supplier_id'));
+ $consumables->where('consumables.supplier_id', '=', $request->input('supplier_id'));
}
if ($request->filled('location_id')) {
- $consumables->where('location_id', '=', $request->input('location_id'));
+ $consumables->where('consumables.location_id', '=', $request->input('location_id'));
}
if ($request->filled('notes')) {
- $consumables->where('notes', '=', $request->input('notes'));
+ $consumables->where('consumables.notes', '=', $request->input('notes'));
}
// Make sure the offset and limit are actually integers and do not exceed system limits
diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php
index 98ed860016..f95cdacf7d 100644
--- a/app/Http/Controllers/Api/DepartmentsController.php
+++ b/app/Http/Controllers/Api/DepartmentsController.php
@@ -50,23 +50,23 @@ class DepartmentsController extends Controller
}
if ($request->filled('name')) {
- $departments->where('name', '=', $request->input('name'));
+ $departments->where('departments.name', '=', $request->input('name'));
}
if ($request->filled('company_id')) {
- $departments->where('company_id', '=', $request->input('company_id'));
+ $departments->where('departments.company_id', '=', $request->input('company_id'));
}
if ($request->filled('manager_id')) {
- $departments->where('manager_id', '=', $request->input('manager_id'));
+ $departments->where('departments.manager_id', '=', $request->input('manager_id'));
}
if ($request->filled('location_id')) {
- $departments->where('location_id', '=', $request->input('location_id'));
+ $departments->where('departments.location_id', '=', $request->input('location_id'));
}
if ($request->filled('tag_color')) {
- $departments->where('tag_color', '=', $request->input('departments.tag_color'));
+ $departments->where('departments.tag_color', '=', $request->input('tag_color'));
}
// Make sure the offset and limit are actually integers and do not exceed system limits
diff --git a/tests/Feature/Accessories/Api/IndexAccessoryTest.php b/tests/Feature/Accessories/Api/IndexAccessoryTest.php
index e14fb3a362..28fd52ef3c 100644
--- a/tests/Feature/Accessories/Api/IndexAccessoryTest.php
+++ b/tests/Feature/Accessories/Api/IndexAccessoryTest.php
@@ -4,7 +4,11 @@ namespace Tests\Feature\Accessories\Api;
use App\Models\Accessory;
use App\Models\AccessoryCheckout;
+use App\Models\Category;
use App\Models\Company;
+use App\Models\Location;
+use App\Models\Manufacturer;
+use App\Models\Supplier;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
@@ -96,4 +100,60 @@ class IndexAccessoryTest extends TestCase implements TestsFullMultipleCompaniesS
])
->assertJson(fn (AssertableJson $json) => $json->has('rows', 1)->where('rows.0.name', 'Accessory With Two Checkouts')->etc());
}
+
+ public function test_can_filter_accessories_by_all_supported_exact_fields()
+ {
+ $user = User::factory()->superuser()->create();
+
+ $targetCompany = Company::factory()->create();
+ $otherCompany = Company::factory()->create();
+ $targetCategory = Category::factory()->forAccessories()->create();
+ $otherCategory = Category::factory()->forAccessories()->create();
+ $targetManufacturer = Manufacturer::factory()->create();
+ $otherManufacturer = Manufacturer::factory()->create();
+ $targetSupplier = Supplier::factory()->create();
+ $otherSupplier = Supplier::factory()->create();
+ $targetLocation = Location::factory()->create();
+ $otherLocation = Location::factory()->create();
+
+ $targetAccessory = Accessory::factory()->create([
+ 'name' => 'Target Accessory',
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'NOTE-A',
+ ]);
+
+ $otherAccessory = Accessory::factory()->create([
+ 'name' => 'Other Accessory',
+ 'company_id' => $otherCompany->id,
+ 'order_number' => 'ORDER-B',
+ 'category_id' => $otherCategory->id,
+ 'manufacturer_id' => $otherManufacturer->id,
+ 'supplier_id' => $otherSupplier->id,
+ 'location_id' => $otherLocation->id,
+ 'notes' => 'NOTE-B',
+ ]);
+
+ $filters = [
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'NOTE-A',
+ ];
+
+ foreach ($filters as $filterKey => $filterValue) {
+ $this->actingAsForApi($user)
+ ->getJson(route('api.accessories.index', [$filterKey => $filterValue]))
+ ->assertOk()
+ ->assertResponseContainsInRows($targetAccessory)
+ ->assertResponseDoesNotContainInRows($otherAccessory);
+ }
+ }
}
diff --git a/tests/Feature/Components/Api/ComponentIndexTest.php b/tests/Feature/Components/Api/ComponentIndexTest.php
index d13c03f5f8..1307a375f8 100644
--- a/tests/Feature/Components/Api/ComponentIndexTest.php
+++ b/tests/Feature/Components/Api/ComponentIndexTest.php
@@ -4,6 +4,10 @@ namespace Tests\Feature\Components\Api;
use App\Models\Company;
use App\Models\Component;
+use App\Models\Location;
+use App\Models\Manufacturer;
+use App\Models\Supplier;
+use App\Models\Category;
use App\Models\User;
use Tests\TestCase;
@@ -54,4 +58,64 @@ class ComponentIndexTest extends TestCase
->assertResponseDoesNotContainInRows($componentA)
->assertResponseContainsInRows($componentB);
}
+
+ public function test_component_index_filters_all_supported_exact_fields()
+ {
+ $user = User::factory()->superuser()->create();
+
+ $targetCompany = Company::factory()->create();
+ $otherCompany = Company::factory()->create();
+ $targetCategory = Category::factory()->create();
+ $otherCategory = Category::factory()->create();
+ $targetSupplier = Supplier::factory()->create();
+ $otherSupplier = Supplier::factory()->create();
+ $targetManufacturer = Manufacturer::factory()->create();
+ $otherManufacturer = Manufacturer::factory()->create();
+ $targetLocation = Location::factory()->create();
+ $otherLocation = Location::factory()->create();
+
+ $targetComponent = Component::factory()->create([
+ 'name' => 'Target Component',
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'COMP-ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'model_number' => 'COMP-MODEL-A',
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'COMP-NOTES-A',
+ ]);
+
+ $otherComponent = Component::factory()->create([
+ 'name' => 'Other Component',
+ 'company_id' => $otherCompany->id,
+ 'order_number' => 'COMP-ORDER-B',
+ 'category_id' => $otherCategory->id,
+ 'supplier_id' => $otherSupplier->id,
+ 'manufacturer_id' => $otherManufacturer->id,
+ 'model_number' => 'COMP-MODEL-B',
+ 'location_id' => $otherLocation->id,
+ 'notes' => 'COMP-NOTES-B',
+ ]);
+
+ $filters = [
+ 'name' => 'Target Component',
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'COMP-ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'model_number' => 'COMP-MODEL-A',
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'COMP-NOTES-A',
+ ];
+
+ foreach ($filters as $filterKey => $filterValue) {
+ $this->actingAsForApi($user)
+ ->getJson(route('api.components.index', [$filterKey => $filterValue]))
+ ->assertOk()
+ ->assertResponseContainsInRows($targetComponent)
+ ->assertResponseDoesNotContainInRows($otherComponent);
+ }
+ }
}
diff --git a/tests/Feature/Consumables/Api/ConsumableIndexTest.php b/tests/Feature/Consumables/Api/ConsumableIndexTest.php
index f6d4fae37f..2a1e08ab6f 100644
--- a/tests/Feature/Consumables/Api/ConsumableIndexTest.php
+++ b/tests/Feature/Consumables/Api/ConsumableIndexTest.php
@@ -4,6 +4,10 @@ namespace Tests\Feature\Consumables\Api;
use App\Models\Company;
use App\Models\Consumable;
+use App\Models\Category;
+use App\Models\Location;
+use App\Models\Manufacturer;
+use App\Models\Supplier;
use App\Models\User;
use Tests\TestCase;
@@ -79,4 +83,64 @@ class ConsumableIndexTest extends TestCase
]);
}
+
+ public function test_consumable_index_filters_all_supported_exact_fields()
+ {
+ $user = User::factory()->superuser()->create();
+
+ $targetCompany = Company::factory()->create();
+ $otherCompany = Company::factory()->create();
+ $targetCategory = Category::factory()->create();
+ $otherCategory = Category::factory()->create();
+ $targetManufacturer = Manufacturer::factory()->create();
+ $otherManufacturer = Manufacturer::factory()->create();
+ $targetSupplier = Supplier::factory()->create();
+ $otherSupplier = Supplier::factory()->create();
+ $targetLocation = Location::factory()->create();
+ $otherLocation = Location::factory()->create();
+
+ $targetConsumable = Consumable::factory()->create([
+ 'name' => 'Target Consumable',
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'CONS-ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'model_number' => 'CONS-MODEL-A',
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'CONS-NOTES-A',
+ ]);
+
+ $otherConsumable = Consumable::factory()->create([
+ 'name' => 'Other Consumable',
+ 'company_id' => $otherCompany->id,
+ 'order_number' => 'CONS-ORDER-B',
+ 'category_id' => $otherCategory->id,
+ 'model_number' => 'CONS-MODEL-B',
+ 'manufacturer_id' => $otherManufacturer->id,
+ 'supplier_id' => $otherSupplier->id,
+ 'location_id' => $otherLocation->id,
+ 'notes' => 'CONS-NOTES-B',
+ ]);
+
+ $filters = [
+ 'name' => 'Target Consumable',
+ 'company_id' => $targetCompany->id,
+ 'order_number' => 'CONS-ORDER-A',
+ 'category_id' => $targetCategory->id,
+ 'model_number' => 'CONS-MODEL-A',
+ 'manufacturer_id' => $targetManufacturer->id,
+ 'supplier_id' => $targetSupplier->id,
+ 'location_id' => $targetLocation->id,
+ 'notes' => 'CONS-NOTES-A',
+ ];
+
+ foreach ($filters as $filterKey => $filterValue) {
+ $this->actingAsForApi($user)
+ ->getJson(route('api.consumables.index', [$filterKey => $filterValue]))
+ ->assertOk()
+ ->assertResponseContainsInRows($targetConsumable)
+ ->assertResponseDoesNotContainInRows($otherConsumable);
+ }
+ }
}
diff --git a/tests/Feature/Departments/Api/DepartmentsIndexTest.php b/tests/Feature/Departments/Api/DepartmentsIndexTest.php
index a5997b5718..71cd32a06c 100644
--- a/tests/Feature/Departments/Api/DepartmentsIndexTest.php
+++ b/tests/Feature/Departments/Api/DepartmentsIndexTest.php
@@ -4,6 +4,7 @@ namespace Tests\Feature\Departments\Api;
use App\Models\Company;
use App\Models\Department;
+use App\Models\Location;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
@@ -87,4 +88,47 @@ class DepartmentsIndexTest extends TestCase
->assertResponseDoesNotContainInRows($departmentA)
->assertResponseContainsInRows($departmentB);
}
+
+ public function test_department_index_filters_all_supported_exact_fields()
+ {
+ $user = User::factory()->superuser()->create();
+ $targetCompany = Company::factory()->create();
+ $otherCompany = Company::factory()->create();
+ $targetManager = User::factory()->create();
+ $otherManager = User::factory()->create();
+ $targetLocation = Location::factory()->create();
+ $otherLocation = Location::factory()->create();
+
+ $targetDepartment = Department::factory()->create([
+ 'name' => 'Target Department',
+ 'company_id' => $targetCompany->id,
+ 'manager_id' => $targetManager->id,
+ 'location_id' => $targetLocation->id,
+ 'tag_color' => '#AA11AA',
+ ]);
+
+ $otherDepartment = Department::factory()->create([
+ 'name' => 'Other Department',
+ 'company_id' => $otherCompany->id,
+ 'manager_id' => $otherManager->id,
+ 'location_id' => $otherLocation->id,
+ 'tag_color' => '#11AA11',
+ ]);
+
+ $filters = [
+ 'name' => 'Target Department',
+ 'company_id' => $targetCompany->id,
+ 'manager_id' => $targetManager->id,
+ 'location_id' => $targetLocation->id,
+ 'tag_color' => '#AA11AA',
+ ];
+
+ foreach ($filters as $filterKey => $filterValue) {
+ $this->actingAsForApi($user)
+ ->getJson(route('api.departments.index', [$filterKey => $filterValue]))
+ ->assertOk()
+ ->assertResponseContainsInRows($targetDepartment)
+ ->assertResponseDoesNotContainInRows($otherDepartment);
+ }
+ }
}