laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.41k stars 10.99k forks source link

withCount and Pagination overrides paginations `columns` part #45449

Closed iquad closed 1 year ago

iquad commented 1 year ago

Description:

When using withCount with pagination, it overrides paginations columns part.

\App\Models\User::paginate(10, ['id', 'email']);

returns

select
  "id"
from
  "users"
limit
  10 offset 0

but

\App\Models\User::withCount('transportations')->paginate(10, ['id', 'email']);

returns

select
  "users".*,
  (
    select
      count(*)
    from
      "transportations"
    where
      "users"."id" = "transportations"."user_id"
      and "transportations"."deleted_at" is null
  ) as "transportations_count"
from
  "users"
limit
  10 offset 0

Steps To Reproduce:

  1. Create new project.
  2. Create relationship.
  3. Query with withCount
driesvints commented 1 year ago

withCount can't be combined with this.

iquad commented 1 year ago

Can't because eloquent not capable or any particular reason? 🤔 On Dec 29, 2022, 14:40 +0300, Dries Vints @.***>, wrote:

withCount can't be combined with this. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>