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

Wrong withCount with hasManyThrough() relations #26623

Closed
mkuzmych opened this issue Nov 26, 2018 · 2 comments
Closed

Wrong withCount with hasManyThrough() relations #26623

mkuzmych opened this issue Nov 26, 2018 · 2 comments
Labels

Comments

@mkuzmych
Copy link

mkuzmych commented Nov 26, 2018

  • Laravel Version: 5.7.9
  • PHP Version: 7.1.6
  • Database Driver & Version: mysql 5.6.25

Description:

Wrong withCount with hasManyThrough() relations

Steps To Reproduce:

Relations

I have relations with parent_id on table categories:
categories
id - integer
categories
id - integer
parent_id - integer
products
id - integer
category_id - integer

Model

class Category extends Model {
    public function products()
    {
        return $this->hasMany('App\Product');
    }
    public function sub_products()
    {
        return $this->hasManyThrough('App\Product','App\Category','parent_id','category_id','id','id');
    }
}

Problem

I make request:

Category::where('id','=',9)->with('sub_products')->withCount('sub_products')->get();

Request return sub_products items, but count return always 0! Thanks!

@staudenmeir
Copy link
Contributor

I can reproduce this. It also affects Category::has('sub_products') queries.

@mkuzmych
Copy link
Author

Yes, with has I reproduce this too, and have problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants