© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
101 replies
shenntek

RelationManager belongsToMany withPivot(['id']) returns Column 'id' in order clause is ambiguous

When attaching an Product item to my Warehouse model which is a manyToMany relationship. I'm getting an SQL error (see below)
the order by should contain the pivot table name ....

i need the "id" because my attachments can be duplicated. I also already have configured:
$table->allowDuplicates()
$table->allowDuplicates()


this is my migration:

Schema::create('product_warehouse', function (Blueprint $table) {

            $table->id();
            $table->foreignId('product_id');
            $table->foreignId('warehouse_id');
            $table->string('quantity');
            $table->text('location_info');
            $table->timestamps();
        });
Schema::create('product_warehouse', function (Blueprint $table) {

            $table->id();
            $table->foreignId('product_id');
            $table->foreignId('warehouse_id');
            $table->string('quantity');
            $table->text('location_info');
            $table->timestamps();
        });


Product Model:
public function warehouses()
    {
        return $this->belongsToMany(Warehouse::class)->withPivot(['id', 'quantity', 'location_info']);
    }
public function warehouses()
    {
        return $this->belongsToMany(Warehouse::class)->withPivot(['id', 'quantity', 'location_info']);
    }

Warehouse Model:

public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class)->withPivot(['id', 'quantity', 'location_info']);
    }
public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class)->withPivot(['id', 'quantity', 'location_info']);
    }


SELECT
  `product_warehouse`.`warehouse_id` AS `pivot_warehouse_id`,
  `product_warehouse`.`product_id` AS `pivot_product_id`,
  `product_warehouse`.`quantity` AS `pivot_quantity`,
  `product_warehouse`.`location_info` AS `pivot_location_info`,
  `product_warehouse`.*,
  `products`.*
FROM
  `products`
  INNER JOIN `product_warehouse` ON `products`.`id` = `product_warehouse`.`product_id`
WHERE
  `product_warehouse`.`warehouse_id` = 1
ORDER BY
  `id` DESC
limit
  50 OFFSET 0
SELECT
  `product_warehouse`.`warehouse_id` AS `pivot_warehouse_id`,
  `product_warehouse`.`product_id` AS `pivot_product_id`,
  `product_warehouse`.`quantity` AS `pivot_quantity`,
  `product_warehouse`.`location_info` AS `pivot_location_info`,
  `product_warehouse`.*,
  `products`.*
FROM
  `products`
  INNER JOIN `product_warehouse` ON `products`.`id` = `product_warehouse`.`product_id`
WHERE
  `product_warehouse`.`warehouse_id` = 1
ORDER BY
  `id` DESC
limit
  50 OFFSET 0
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Column 'name' in where clause is ambiguous
FilamentFFilament / ❓┊help
3y ago
Column 'id' in where clause is ambiguous in edit record page
FilamentFFilament / ❓┊help
2y ago
ambiguous column name: id
FilamentFFilament / ❓┊help
2y ago
Filter belongsToMany relationmanager
FilamentFFilament / ❓┊help
3y ago