Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When having withCount & where at the same time - the results are not paginated, search and ordering don't work #1471

Closed
FilipQL opened this issue Oct 26, 2017 · 5 comments

Comments

@FilipQL
Copy link

FilipQL commented Oct 26, 2017

Summary of problem or feature request

When having withCount & where at the same time - the results are not paginated, search and ordering don't work.

Code snippet of problem

When I use withCount & where at the same time - the results are not paginated (DataTable shows Showing 0 to 0 of 0 entries), search and ordering don't work:

        $articles = Article::select('articles.*')
            ->withCount('comments')
            ->with(['market', 'category', 'user'])
            ->where('articles.market_id', 1);

mozilla firefox 2017-10-26 17 56 09

When I remove where and leave withCount:

        $articles = Article::select('articles.*')
            ->withCount('comments')
            ->with(['market', 'category', 'user']);

... everything works OK. Also, when I remove withCount and leave where:

        $articles = Article::select('articles.*')
            ->with(['market', 'category', 'user'])
            ->where('articles.market_id', 1);

... everything works OK. Do you know why is this happening and how can I fix this?

If it can help, here are queries for the case where withCount and where are used at the same time:

mozilla firefox 2017-10-26 18 07 19

System details

  • Operating System: Ubuntu 16.04 (Laravel Homestead)
  • PHP Version: PHP 7.1 (Laravel Homestead)
  • Laravel Version: 5.4.36
  • Laravel-Datatables Version 8.3.1
@FilipQL FilipQL changed the title When having withCount & where at the same time - the results are not paginated and ordering doesn't work When having withCount & where at the same time - the results are not paginated, search and ordering don't work Nov 1, 2017
@swash13
Copy link

swash13 commented Nov 9, 2017

same issue, if i write this in my model it's working OK:
return $this->hasMany(JobAnalytic::class);

But if i will add where condition - no paginate and sorting and search:
return $this->hasMany(JobAnalytic::class)->where('job_analytics.action_type', JobAnalytic::APPLY_NOW_BTN_CLICKED);

@ikerasLT
Copy link
Contributor

Same issue here.

Just to point to the right direction:

Row count query seems to omit with_count queries but not associated bindings:
8f247c3b-d29d-4e78-9192-42f8c9f92858

yajra added a commit that referenced this issue May 12, 2018
* 8.0:
  Bump v8.5.1 🚀
  [8.0] Reset select bindings for count query (#1730)
  Classify join statements as a complex query. Fix #1600, #1730, #1471
@yajra
Copy link
Owner

yajra commented May 12, 2018

Can you please check again using v8.5.1, this be fixed by #1737 and #1730. Thanks!

Copy link

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 20, 2023
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants