rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.79k stars 339 forks source link

[Bug]: Bulk action not working properly and crashes #1930

Closed isigillo closed 2 months ago

isigillo commented 2 months ago

What happened?

I have a list of records (purchase requests) and each one has a timeline to track status changes (see notes for details). I enabled bulkActions to "approve" many rows at once

How to reproduce the bug

  1. when I select a row, all row are selected
  2. where I check "select all" it crashes

Package Version

3.4.17

PHP Version

8.1.x

Laravel Version

10.48.20

Alpine Version

No response

Theme

Tailwind 3.x

Notes

I have a list of records (purchase requests) and each one has a timeline to track status changes. The current "status" of the item is the latest timeline entry On purchase Request model I have

public function timelines() {
        return $this->hasMany(Timeline::class);
    }

and

public function latestStatus() {
        return $this->timelines()->latest()->first();
    }

In PurchaseRequestTable component I have this builder function

public function builder(): Builder {
        $query = PurchaseRequest::query()
            ->with(['customer', 'pm', 'user', 'timelines', 'jobTicket', 'status']);
        return $query->select(); // Select some things
    }

In debug mode I see this query when I select a value for filer status

`


"query" => """
    select *, `purchase_requests`.`id` as `id`, `purchase_requests`.`code` as `code`, `purchase_requests`.`date` as `date`, `purchase_requests`.`customer_order` as `customer_order`, `purchase_requests`.`description` as `description`, `jobTicket`.`code` as `jobTicket.code`, `supplier`.`name` as `supplier.name`, `user`.`name` as `user.name`, `purchase_requests`.`is_billable` as `is_billable`, `purchase_requests`.`is_urgent` as `is_urgent` from `purchase_requests` left join `job_tickets` as `jobTicket` on `purchase_requests`.`job_ticket_id` = `jobTicket`.`id` left join `suppliers` as `supplier` on `purchase_requests`.`supplier_id` = `supplier`.`id` left join `users` as `user` on `purchase_requests`.`user_id` = `user`.`id` inner join (select status, purchase_request_id,

                                        row_number() over (partition by purchase_request_id order by created_at desc) as rn

                                        from timelines) as t on `t`.`purchase_request_id` = `purchase_requests`.`id` and `rn` = 1 where `t`.`status` = ? and `purchase_requests`.`deleted_at` is null order by `purchase_requests`.`id` desc limit 25 offset 0
``` `

### Error Message

see this [Flare Laravel Error Tracking](https://flareapp.io/share/LPdeK4g7)
isigillo commented 2 months ago

I find the cause of the error: I had the primary key $this->setPrimaryKey('purchase_requests.id'); I changed to $this->setPrimaryKey('id');

and it works