You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summarize on many-to-many relationship in Relationship Manager results in a SQL ERROR: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id'
#12501
In a RelationshipManager::table() I defined some columns to display on the detail page of the parent model.
Now, there are some numbers in it for knowing the amount of a product.
When I call ->summarize(Sum::make()) on a numeric column, it throws the SQL Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id'
Expected behavior
Instead of throwing a SQL Exception, I should get the summarized amount of all the entries in that table.
Steps to reproduce
create 2 models, for example: order and product
create a pivot model with some pivot columns to connect the models of step 1
make a resource for the order model php artisan make:filament-resource OrderResource -G
make a relationship manager for this resource php artisan make:filament-relation-manager OrderResource products title
add some columns to the table of the relationsManager 1 of the column should be a numeric value
// This cause the SQL error:
->summarize(Tables\Columns\Summarizers\Sum::make()->using(
fn(Builder$builder) => $this->getOwnerRecord()->products()->sum('products.price')
))
Thank you @dmitry-udod for a solution that may work for now, I only had to change the name of the column of sum to order_product.price because I needed the pivot table.
But I see this as a quick fix and think it should not be the case for a default flow when using many-to-many with pivot columns. But that is my opinion.
Package
filament/filament
Package Version
v3.2.71
Laravel Version
v11.4.0
Livewire Version
v3.4.10
PHP Version
v8.3.6
Problem description
In a RelationshipManager::table() I defined some columns to display on the detail page of the parent model.
Now, there are some numbers in it for knowing the amount of a product.
When I call
->summarize(Sum::make())
on a numeric column, it throws the SQL Exception:SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id'
Expected behavior
Instead of throwing a SQL Exception, I should get the summarized amount of all the entries in that table.
Steps to reproduce
php artisan make:filament-resource OrderResource -G
php artisan make:filament-relation-manager OrderResource products title
->summerize()
on the numeric column.Reproduction repository
https://github.com/GekkeGlennDev/filament-sql-issue
Relevant log output
The text was updated successfully, but these errors were encountered: