【问题标题】:Laravel hasManyThrough wrong withCount and good ->count()Laravel hasManyThrough wrong withCount 和 good ->count()
【发布时间】:2018-05-19 22:55:05
【问题描述】:

我有 hasManyThrough 关系。

public function orders()
{
    return $this->hasManyThrough(Order::class, Customer::class, 'email', 'customer_id', 'email', 'email');
}

在这样的事情之后......

{{ $user->orders->count() }}

我为已定义的用户收到了 14 个订单。很好。但是……

经过类似的代码...

User::withCount('orders')...

同一用户的计数不同。

我在调试栏 sql 信息中看到错误。

应该是 users.email = customers.email...

有办法改变吗?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    这已在 Laravel 5.5.22 中修复:https://github.com/laravel/framework/pull/22071

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-29
      • 2014-09-19
      • 1970-01-01
      • 2019-08-06
      • 2020-01-30
      • 2019-03-27
      • 2023-03-28
      • 2021-03-18
      相关资源
      最近更新 更多