laravel-enso/tables

Wrong table pagination count using soft-delete trait

Closed this issue · 3 comments

This is a bug.

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you check the documentation?
  • Did you perform a cursory search?

Description

This is somehow related to "Table pagination fails when multi-select filters are applied" #217, where the issue still persists and has a wider effect.

I have the following App\Tables\Builders\ModelTable.php file:

...
public function query(): Builder
{
   return Model::selectRaw('
            model.id,
            model.name as rserverName,
            model.ip,
            model.description,
            model.status
        ');
}
...

So as you can see, it's a simple query, no joins, no aggregation, no scope method call, no nothing.

My Model table json (App\Tables\Templates\models.json) definition has :

"countCache": false,

My Model class has these traits used:

 use HasFactory, SoftDeletes, TableCache;

I have a total of 20 entries in my DB, from which 2 are soft-deleted:
image

When loading the table, I see 2 pages (with 10 rows per page):
Page 1:
image
Page 2:
image

As you can see, page 2 has 2 missing rows (which are reflected also in the actual table rows) but the total count is still 20, as if the soft-delete is taken in account when loading the table data, but not when doing the counting for pagination.

Even more, if I add a 21st entry in DB, I will get page 3 shown, but not accessible, since there are no visible entries to be shown there. A redirect to page 1 is done.

Could still be something from here:
vendor/laravel-enso/tables/src/Services/Data/Builders/Meta.php or even vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php

Hi @robbykrlos,
could you please test it with this fix/softDeletesWithApplyingScopes ?
thank you

And call php artisan enso:tables:clear to delete local table cache

Yes. Seems to be working with fix/softDeletesWithApplyingScopes. I see the fix is quite recent :-)
Thank you & sorry I did not searched more - apparently I used some keywords that did not show #226

Duplicated.

Fixed by Entries count <> Rows if you have deleted rows #226